- Home /
Question by
Wilko343 · Nov 16, 2012 at 10:14 PM ·
gameobjectcomponent
Adding a script component through scripting
I want to add a script component like this:
AddComponent(Script);
I'm creating a new gameobject via scripting. Is is it even possible to do this?
Comment
Answer by FakeBerenger · Nov 16, 2012 at 11:32 PM
Sure thing. YOu need the reference of the gameObject you want to a the script on though. In your case, the instance you just created. You can use the class name as a string, or the type with typeof().
Note that if you're creating the GameObject with the constructor, you can add as parameter the component you want it to have, all in a single line !