Game Development Reference
In-Depth Information
Figure 2-32. Vector2 coordinate (x, y) values displayed in the Console panel
Unity provides some commonly used static variables in the Scripting Reference (Figure 2-33 ).
Figure 2-33. Vector2 static variables described in the Unity Scripting Reference
Replace myVector with Vector2.up in the Debug.Log statement to confirm that you get (0, 1) as the
output in the Console. If you are wondering why there isn't a .down or .left , you just use -.up and
-.right for their opposites.
The length of a vector is called its magnitude . You may or may not remember using the Pythagorean
Theorem in geometry class to find the distance between two points, but Unity steps in here for you
with Vector2.magnitude when you need to determine the distance between game objects. Click on
“magnitude” to take a quick look at the description of Vector2.magnitude (Figure 2-34 ).
Figure 2-34. Vector2.magnitude description from the Unity Scripting Reference
Search WWH ::




Custom Search