Game Development Reference
one name. The capital makes the variable name more readable as single
words are easier to read. A variable name could also be written
using the underscore to separate words. This is a totally personal preference
and makes no difference to the compiler; however, naming conventions 4
for variable names is recommended with the first letter being in lowercase.
Because conventions can vary slightly between languages, it will not be
covered in this topic.
Although they could be placed in a variety of locations, the best place
is at the top because they are easy to find. We will examine other
types of variables in later sections.
Consider the script in Listing 1.10 .
of a GameObject on Game Start
private var objScaleX: float = 0.5;
function Start ()
transform.localScale.x = objScaleX;
The line showing the variable declaration is shown in bold . Note, do not use
bold in your own code; this is for illustrative purposes only. The keyword
in which it is declared. It cannot be seen for use by other code files. You can
you will want to be able to share the variable contents between these. In
this case, you would declare an exposed variable. In this example, the code
would be the same as Listing 1.10 , except the private keyword would be
When a variable becomes exposed, it also appears in the Inspector of
the Unity Editor where values can be entered manually. The difference
is illustrated in Figure 1.26 .
4 For more information about naming conventions, see http://en.wikipedia.org/wiki/