Array question

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);
		
    }
}
}

It seems to me that you might have to use OnCollisionStay instead of Enter because your neighbouring cubes are already touching by the time they catch fire.

The first one will trigger because there is the change of state from not touching to touching, but there’s no similar change for the stationary cubes. You can check by printing the gameobject names that are populating your Burn array; there shouldn’t be additions past the first one if I’m right.

Quick Edit: Have you considered using trigger events instead of collision events for spreading the fire? if there’s no movement, its less costly with the same effect, I think.

ChrisD is correct that the problem is that you’re using OnCollisionEnter. I’d advice using Physics.OverlapSphere() rather then OnCollisionStay however. Ericksson also brings up a good point that as soon as you have a script execute Destroy() on the gameObject executing the very script, the script will no longer be executed.

Edit: example of overlapsphere.

execute this when or while you’re on fire. Only destroy it after setting the other objects on fire.

var nearObjects : collider[] = Physics.OverlapSphere( transform.position, 1 )
for( var object : collider in nearObjects ) {
    if( object.gameObject.tag == "Burnable" ) {
        //burn it
    }
}