I’m making an array-based script (first in my life!) and I’ve got a problem. My level is 8 cubes in a row touching, all with the Burnable tag. I then drop a Burning - tagged object onto the first one. It is set on fire, and burns out. It’s tag changes. But the next one does not burn. What is wrong with my script and what should I do?
EDIT: Added your suggestions. But it does not repeat. The first cube burns the second cube, which then burns. The third cube sits there smugly. What is wrong now?
var fire : Transform;
var burntReplacement : Transform;
var burnTime = 5;
var arr = new Array ();
var ready = true;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Burnable"){
arr.Push (other.gameObject);
print (arr[0]);
print ("It may have worked!");
}
if(other.gameObject.tag == "Burning"){
Instantiate (fire, transform.position, transform.rotation);
gameObject.tag = "Burning";
burn();
yield WaitForSeconds (burnTime);
Instantiate (burntReplacement, transform.position, transform.rotation);
Destroy (gameObject);
}
}
function burn (){
var nearObjects : Collider[] = Physics.OverlapSphere( transform.position, 1 );
for( var object : Collider in nearObjects ) {
if( object.gameObject.tag == "Burnable" ) {
object.gameObject.tag = "Burning";
Instantiate (fire, object.gameObject.transform.position, transform.rotation);
}
}
}