Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>();

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading