- Home /
Past a Type Script from the inspector
Hello:
I am trying to do a script when I could pass a type script with the inspector
Something like this:
public class TileNodeTest < T > : MonoBehaviour where T : MonoBehaviour
{
public T type;
private void OnDrawGizmosSelected()
{
List < T > objectList = this.gameObject.GetComponents< T > ();
foreach (T objectTest in objectList)
{
Gizmos.DrawSphere(objectTest.transform.position + Vector3.up * 5.0f, 0.5f);
}
}
}
But It does not work. It is possible to do this? How?
It's not clear how you want to use this generic class. Unity can't directly handle generic classes. If you derive a class from this one it can be used as script, but not this class.
Can you add an example usage of your class
Yes sure:
What I want is to take an array with Physics.OverlapSphere and then, filter them if they have or not a component. The component I would like to choose from the inspector because I want the class to debug and I'd want to change the component
Do you need to do this in the Unity editor? So are you writing an editor script? In this case you should create an EditorWindow and display a $$anonymous$$onoScript ObjectField.
You can't make a "type field" in runtime classes since System.Type can't be serialiced by unity. It's still not really clear what you want to do and what's the purpose of your generic class.
Btw, the code in your class makes not much sense. You use GetComponents which will return a list of all components on "this" gameobject. Your DrawSphere will by at the same position for each component since all are attached to the same object.
Ok, I'll forget this. I'm doing with a enum and a Generic method
I know about the code, thank you ;-)
Your answer
![](https://koobas.hobune.stream/wayback/20220613093115im_/https://answers.unity.com/themes/thub/images/avi.jpg)