- Home /
Why we have to use getcomponent instead of a simple reference ?
myclass a = new myclass();
vs
myclass a = getcomponent<scriptname>();
what is the difference ?
Comment
Best Answer
Answer by Camilohoyos16 · Aug 16, 2017 at 05:15 PM
Becuase with a simple reference you are calling a simple script, just script, which doesn't control any gameobject. So you need to use getcomponent to have a script of the gameobject and control variables of that gameobjects.
Answer by TheSOULDev · Aug 16, 2017 at 04:53 PM
First creates a new class of type myclass.
Second one creates a reference to an existing class on the object and I don't think it'll work without a cast.