标题: [脚本章节]Overview: Vectors 向量 [打印本页] 作者: 驰骋的风 时间: 2012-10-11 10:22 标题: [脚本章节]Overview: Vectors 向量 Unity uses the Vector3 class throughout to represent all 3D vectors. The individual components of a 3D vector can be accessed through its x, y and z member variables.
Note: This only works on JavaScript and Boo. In C# you will have to create a new instance of a Vector and assign it. var aPosition : Vector3;
Unity使用 Vector3 类来表现所有的3D向量.我们可以通过他的x,y和z成员变量获得3D向量的组件.
var aPosition : Vector3 ;
aPosition.x = 1;
aPosition.y = 1;
aPosition.z = 1;
You can also use the Vector3 cons***ctor function to initialise all components at once.
你也能使用 Vector3 构造函数初始化所有的组件.
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Vector3 aPosition = new Vector3(1, 1, 1);}
var aPosition = Vector3(1, 1, 1);
Vector3 also defines some common values as constants.
Vector3 也定义了一些固定的常用值.
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Vector3 direction = Vector3.up;}
var direction = Vector3.up ; // 等同于 Vector3(0, 1, 0)
Operations on single vectors are accessed the following way:
规范化向量可以使用下面的方法:
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public void Awake() {SomeVector.Normalize();}}
SomeVector.Normalize();
And operations using multiple vectors are done using Vector3 class functions:
使用 Vector3 类函数计算多个向量的情况:
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Vector3 oneVector = new Vector3(0, 0, 0);public Vector3 otherVector = new Vector3(1, 1, 1);public float theDistance = Vector3.Distance(oneVector, otherVector);}
(Note that you have to write Vector3. in front of the function name to tell Javascript where to find the function. This applies to all class functions.)
You can also use the common math operators to manipulate vectors: combined = vector1 + vector2;
See the documentation on the Vector3 class for the full list of operations and properties available.
(注意你必须在函数名之前写上Vector3.以便Javascript能找到那个函数.这个规则也应用于所有的类函数.)
你也能使用常见的数学运算操作向量:combined = vector1 + vector2;
查看文档 Vector3 类可以获得更过相关信息.
来源:Unity3D圣典 更多分享尽在Web3D纳金网http://www.narkii.com/
————————————————————————
Subsections 章节
[脚本章节]Scripting Overview 脚本概述
[脚本章节]Overview: Script compilation 脚本编译(高级)
[脚本章节]Overview: Performance Optimization 性能优化
[脚本章节]Overview: The most important classes 重要的类
[脚本章节]Overview : Writing Scripts in C# 使用C#书写脚本
[脚本章节]Overview: Coroutines & Yield 协同程序 & 中断
[脚本章节]Overview: Instantiate 实例
[脚本章节]Overview: Member Variables & Global Variables 成员变量 & 全局变量
[脚本章节]Overview: Vectors 向量
[脚本章节]Overview: Accessing Other Game Objects 访问其他游戏物体
[脚本章节]Overview: Accessing Other Components 访问其他组件
[脚本章节]Overview: Keeping Track of Time 记录时间
[脚本章节]Overview: Common Operations 常用操作