How to add custom class as a component to gameobject in unity?

So I have a prefab which is Instantiated in run time, to that prefab I create and add another game object with components Image as a child. Now here how can I add a custom class data as component to the newly created child of prefab?

>Solution :

To be able to add your custom script to the game object on the scene, this custom script must be inherited from MonoBehaviour. After that, you can add your class do game object in the inspector (by clicking Add Component button, see image below) or from code by calling


enter image description here

Leave a Reply