It is my understanding, that if you attatch a Script derived from MonoBehaviour to a GameObject, only one Class (the one with the same Name as the Script itself) can be added to the GameObject... What exactly will be the consequences of this?
I assume you will not be able to find the GameObject, when using FindObjectOfType with one of the non-scriptname-classes?
Will you be able to get the non-scriptname-classes with GetComponent?
What else will fail?
How will you access the other Classes?
What about Scripts derived from other classes? (especially "ScriptableObject"?)
So far I fail to see any merits of declaring multiple Classes in one Script... except maybe not having a gazillion mini-Scripts lying around in the ProjectPane... Doesn't seem to be in any relation to the (assumed) down-sides... What am I missing?
Thanks & Greetz, Ky.
It only really makes sense to declare one MonoBehaviour class in a script file. However you may have cause to declare other 'helper' classes which are used by instances of your monobehaviour class.
For example, you may have enemies in your game, and those enemies might have designated targets. Now, you might initially decide that the 'target' of each enemy could simply be a reference to the target gameobject or transform, but suppose you want to contain more data in a 'target' object, such as 'priority', 'last fired at', 'last seen position', etc.
In this case you might decide to declare 'target' as a class in its own right, but since this is only ever instantiated and used by the 'enemy' object, it might make sense to include this class declaration in the enemy script file.
Ultimately this comes down to aesthetics - there's nothing stopping you from creating a separate script file for your 'target' class, even though it doesn't derive from MonoBehaviour.