ho il seguente metodo:Il tipo 'T' non può essere utilizzato come parametro di tipo 'T' nel tipo generico o di un metodo
protected T AttachComponent<T>(){
T gsComponent = gameObject.GetComponent<T>();
if(gsComponent == null){
gsComponent = gameObject.AddComponent<T>();
}
return gsComponent;
}
Sulla linea AddComponent
sto ottenendo il seguente errore:
The type 'T' cannot be used as type parameter 'T' in the generic type or method 'GameObject.AddComponent<T>()'.
There is no boxing conversion or type parameter conversion from 'T' to 'UnityEngine.Component'.
Non sono sicuro di cosa posso fare per correggere questo errore, perché non posso farlo?
si sarebbe sicuramente farlo ** ** con un'estensione in C#. Ecco un tutorial per tutti i principianti che leggono http://stackoverflow.com/a/35629303/294884 Spero che aiuti! – Fattie