system
1
I'm trying to get it to instantiate an object every time a ball hits a bucket, and when there are no more balls left to instantiate something else. Here is the script...
var total : float = 2;
var firework : GameObject;
var celebration : GameObject;
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Bucket"){
print (total--);
var instance : GameObject = Instantiate(firework, transform.position, transform.rotation);
}
}
function Update(){
if (total = 0);
var instance : GameObject = Instantiate(celebration, transform.position, transform.rotation);
}
Any ideas?
DaveA
2
if (total = 0);
You probably want
if (total == 0) two = signs, no semicolon
When you fix that, it will instantiate one of those things every frame as long as total == 0, which is probably NOT what you want. You should instantiate when the determination is made, or otherwise set a boolean variable or something saying that you have instantiated that object, so as to avoid doing it again every frame.
Check that the let us know
Jessy
3
Use ints. Floats are not really suitable for equality comparisons. Also, once you get that working, your current code is going to instantiate celebration continuously. Move that code to the Collision.