Game Development Reference
In-Depth Information
default:
print ("It's your turn - roll!");
break;
}
}
Here is a case where you are declaring a variable but not assigning a value right away. Instead,
when the Start() function is called, the diceRoll variable is assigned a randomly generated number
between 1 and 6.
Random number generation is another common function in games for determining things such as
the location of new game objects appearing in the scene or the number of enemies in the next attack
wave. From the line of code diceRoll = Random.Range(1, 6); you can probably guess what is going
on, but go ahead and +' on Random.Range for the Scripting Reference (Figure 2-27 ):
Figure 2-27. Random.Range description from the Unity Scripting Reference
Just as you suspected, when the Start() function is called, diceRoll is assigned a randomly generated
number based on the two arguments in the parentheses, min and max . Notice these parameters are
“inclusive,” or you would have to use different arguments to generate the numbers 1 through 6.
 
Search WWH ::




Custom Search