- Home /
The question is answered, right answer was accepted
Can someone tell me whats the difference between these?
im wondering whats the difference between:
var myVar : Vector3 = new Vector3(1,1,1);
-and
var myVar : Vector3 = Vector3(1,1,1);
-or using them in Update function: function Update () { myVar = new Vector3(2,2,2); } -and function Update () { myVar = Vector3(2,2,2); }
So can someone explain the difference for me? I mean whats the difference with "new" keyword and without it?
Answer by FlaSh-G · Jun 23, 2017 at 05:37 PM
Both works in UnityScript because UnityScript is heavily based on JavaScript, which isn't an object oriented language by heart, but rather "kinda supports it" also. UnityScript is trying to mimic JavaScript every now and then, which is the season for the existence of the print function, which is the only lowercase function in all of Unity.
This is also why it supports using the new keyword or omitting it, because that's somehow similar to the weird situation with the keyword in JavaScript land.
Long story short: For all I know, it doesn't make a difference if you use it or not, just like it doesn't make a difference whether you use print or Debug.Log.
Follow this Question
Related Questions
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. 2 Answers
Where to allocate class fields in a MonoBehaviour ? 1 Answer
A curious case of "new" keyword LogWarning when creating monobehaviours. 0 Answers
Having trouble with static references. 1 Answer
Store Multiple values in one variable 2 Answers