문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top