- Home /
Countdown code not working
I'm trying to instantiate an object once the countdown = 0. So what is wrong with my code? (it instnatiates after one collision, rather than two.)
var total : int = 2; var firework : GameObject; var celebrationMaker : GameObject; var myLevel : String;
function OnCollisionEnter(theCollision : Collision) { if(theCollision.gameObject.name == "Sphere") {
(total--);
print (total);
var instance : GameObject = Instantiate(firework, transform.position, transform.rotation);
if (total == 0);
Application.LoadLevel(myLevel);
}
}
Answer by Statement · Mar 27, 2011 at 10:43 AM
It looks like you don't bother to check for instanting on the second hit. However it seems to load a new level then.
var total : int = 2; var firework : GameObject; // var celebrationMaker : GameObject; // var myLevel : String;
function OnCollisionEnter(theCollision : Collision) { if(theCollision.gameObject.name == "Sphere") { if (--total == 0) { Instantiate(firework, transform.position, transform.rotation);
// But... you surely can't load a new level then
// or you'd miss out on the spawned item?
// Application.LoadLevel(myLevel);
}
}
}
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Changing variables in GUI? 0 Answers
Gun Script Help 2 Answers
How to use Enum? 1 Answer