Reputation: 5
I'm trying to do something pretty specific
public class EnableComponent <T> : ScriptableEvent
{
public EnableComponent (GameObject body, bool state = true)
{
body.GetComponent<T>().enabled = state;
}
}
Now this doesn't work, gives something like "The type 'T' cannot be used as type parameter 'T' in the generic type or method."
I tried to do a bit of searching, and the best I found was a short discussion on why this doesn't work in java.
I've tried implementing the same thing by passing a Type parameter but couldn't quite figure it out. I'm pretty sure this would be the way to go, just not exactly sure how to get it to work.
Just hoping someone has a suggestion on a way to implement the above logic.
Thanks in advance.
Upvotes: 0
Views: 173