Question

I come from other programming languages and I am new to Unityscript. I am trying to understand what a Unityscript code is doing.

I found this line

var guiTouchPos : Vector2 = touch.position - guiTouchOffset;

What kind of declaration is this? What is this line doing? Wouldn't it be easy to write

var guiTouchPos = touch.position - guiTouchOffset;

as I don't see Vector2 being used anywhere in the code?

is the line assigning the subtraction to both variables?

thanks.

Was it helpful?

Solution

That is not JavaScript, it's ActionScript 3 or UnityScript. the : indicates a type declaration.

OTHER TIPS

That's invalid syntax in JavaScript, so as written that cannot work.

UPDATE

The syntax is valid in ActionScript, and the part immediately after the colon (Vector2 here) indicates the type of the variable being declared; it's also apparently valid and means the same thing in the JavaScript-like scripting language in Unity, which it seems from Chuck's answer is apparently what the code was originally written for. From what I've just read about Unity's "JavaScript", it's not compatible with any version of the language and should not be called JavaScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top