Unityscript - 这是什么样的声明?
我来自其他编程语言,对 Unityscript 还很陌生。我试图了解 Unityscript 代码在做什么。
我发现了这一行,
var guiTouchPos : Vector2 = touch.position - guiTouchOffset;
这是什么类型的声明?这条线在做什么? 编写起来不是很容易吗
var guiTouchPos = touch.position - guiTouchOffset;
因为我没有看到 Vector2 在代码中的任何地方使用,所以
?是将减法分配给两个变量的行?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是 JavaScript,而是 ActionScript 3 或 UnityScript。
:
表示类型声明。That is not JavaScript, it's ActionScript 3 or UnityScript. the
:
indicates a type declaration.这是 JavaScript 中的无效语法,因此无法正常工作。
UPDATE
该语法在 ActionScript 中有效,冒号后面的部分(此处为
Vector2
)指示所声明的变量的类型;它显然也是有效的,并且在 Unity 中类似 JavaScript 的脚本语言中意味着同样的事情,这似乎来自 Chuck 的答案 显然是代码最初编写的目的。从我刚刚读到的有关 Unity 的“JavaScript”的内容来看,它是与该语言的任何版本都不兼容,不应称为 JavaScript。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.Vector2 是一个类型声明:http://www.cs.sjsu。 edu/~rucker/asteroids/html/Vector2.html
你在为 iOS 编写一些东西吗? http://forum.unity3d.com/threads/51609-如何-使角色跳转
Vector2 is a type declaration : http://www.cs.sjsu.edu/~rucker/asteroids/html/Vector2.html
Are you writing something for iOS? http://forum.unity3d.com/threads/51609-How-to-make-character-JUMP