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?
CodePudding user response:
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
gameObjToAddComponent.AddComponent<MyAwesomeComponentType>();