|
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;
aPosition.x = 1;
aPosition.y = 1;
aPosition.z = 1;
You can also use the Vector3 constructor function to initialise all components at once.
Vector3 also defines some common values as constants.
Operations on single vectors are accessed the following way:
And operations using multiple vectors are done using Vector3 class functions:
(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.