Game Development Reference
In-Depth Information
Math is necessary to game development, but for those of you who don't get a special thrill from
solving math problems for fun, I have great news: Unity provides tons of built-in math functions for
you. After all, doing routine calculations super-fast is what computers do best, and the purpose here
is to facilitate your overall game development.
Mathf is one of the collections of handy math variables and functions provided by Unity.
In MonoDevelop, update your code to look like this:
#pragma strict
function Start () {
Debug.Log(Mathf.PI);
}
Click on Mathf.PI , then press +' to open up its Unity Scripting Reference (Figure 2-24 ):
Figure 2-24. Mathf.PI description from the Unity Scripting Reference
Here you find that Mathf.PI is a static variable of data type float. The value of pi is constant, and a
variable that is static means that it won't let your code change the value that Mathf.PI is holding.
Remember that when you create a function, the argument type has to match the data type it is
accepting. The reference helpfully informs you that it is a float data type, and provides short sample
code for how you might use it.
Run your script and you'll find that you don't get nearly as many decimal places displayed in the
console as is shown in the reference. That's okay—it's unlikely that you'll need more precision than
this in common game usage.
Click on the blue “Mathf” in the title of the Scripting Reference to get the complete list of the Mathf
variables and functions (Figure 2-25 ).
 
Search WWH ::




Custom Search