Hello all
I’m still struggling to grasp why we need to use the keyword “new” when assigning a Vector3 to a variable. Can anyone shed some light on this?
Thanks
Hello all
I’m still struggling to grasp why we need to use the keyword “new” when assigning a Vector3 to a variable. Can anyone shed some light on this?
Thanks
Hi,
You use the new keyword to instantiate (create) a new instance of a class, or struct in this case, e.g. a new object. They can also be used to invoke specific constructors, in the case of a class for example which has overloaded constructors.
If you think of it like using a cookie cutter, the shape of the cookie cutter could be thought of as the class or struct (the template), when you press it into the cookie dough you get a new instance of the shape.
You can then set member variables on that instance to your specific values. If you cut into the dough again, you get another new cookie in the same shape, but perhaps this time you set different member variable values - perhaps the number or colour of gummy buttons on the cookie for example.
Hope this helps.
See also;
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.