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?
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?
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 !