Game Development Reference
In-Depth Information
Now the calculation takes the z component value into account. Update your code to find the
magnitude of a three-dimensional vector like so:
#pragma strict
function Start () {
var myVector : Vector3 = Vector3(3, 4, 12);
Debug.Log(myVector.magnitude);
}
Play-test, and the Console should display a magnitude of 13.
Note
“Play,” “Run,” “Test,” “Enter play mode,” “Play to test,” and “Playtest” are all interchangeable terms
for playing the scene in the Unity editor Game view.
Whether you are using 2D or 3D vectors, these variables, functions, and operators comprise a good
portion of the basic tools for handling gameplay decisions based on the locations and directions of
your various game objects. Now you know how to declare variables including structs like Vector2
and Vector3, how to call functions to process the data in the variable, and where to find the built-in
Unity functions.
Summary
You now know how to use the Unity scripting editor MonoDevelop, and have been introduced
to basic programming terms and concepts—good job! While this chapter gives you a necessary
foundation by serving as both an introduction and a reference, from here on out you will get to see
the result of your scripts on game objects within the Unity editor. And by results I mean you are on
your way to more action, explosions, and sound effects—woo!