- Home /
Question by
Muzz 1 · Apr 06, 2011 at 07:51 PM ·
javascriptinstantiateswitchswitch-case
Switch Statements
What's wrong with my Switch Statement?
var block : GameObject;
var faster : GameObject;
var smoke : GameObject;
var slower : GameObject;
var numberOfBlocks : float = 10.0;
var timeBetweenBlocks : float =2.0;
var BlockNumber : int = 0;
function Update () {
if (numberOfBlocks > 0){
numberOfBlocks--;
var position = Vector3(0, Random.Range(-5, 5), Random.Range(10, 300));
BlockNumber = Random.Range (1, 5);
print (BlockNumber);
switch (BlockNumber){
case ("1"):
Instantiate(block, position, Quaternion.identity);
break;
case ("2"):
Instantiate(faster, position, Quaternion.identity);
break;
case ("3"):
Instantiate(smoke, position, Quaternion.identity);
break;
case ("4"):
Instantiate (slower, position, Quaternion.identity);
break;
case ("5"):
print ("No block this time");
break;
}
It generates a random number, but doesn't actually make anything.
Comment
Best Answer
Answer by DaveA · Apr 06, 2011 at 07:54 PM
Random.Range generates integers, but your cases are strings. Take out the quotes on them