How can I make this work? I want to pass in the name and type of control that I’m looking for, and return the object with generics. However I can’t seem to get it to work with the object type parameter. And I don’t want to pass an object into it.
Build error line #4: ‘Text’ is a type, which is not valid in the given context.
private void Start()
{
Text myTextBox = GetControl("txtMsg", Text);
}
public T GetControl<T>(string controlname, T type) where T : UnityEngine.Object
{
return GameObject.Find(controlname).gameObject.GetComponent<T>();
}
I know I can pass in an Text object in the parameter but I don’t want to do that. I just want to specify the type of object i want it to return.
Any help is much appreciated. Thanks