I would like to get all of the custom scripts attached to a GameObject without knowing their types prior to retrieving them. Is this even possible?
All component that are attached to a GameObject must inherits from UnityEngine.Component
.
Therefore a simple code like this one can retrieve them all:
Component[] components = gameObject.GetComponents(typeof(Component));
If your are looking for scripts only, then MonoBehaviour
is the base class:
MonoBehaviour[] scripts = gameObject.GetComponents(typeof(MonoBehaviour));
After that, you can get the type with:
Debug.Log(components*.GetType()); // this use C# reflection*
or:
Debug.Log(scripts*.GetType()); // this use C# reflection*