# store unique variable on first OnTriggerEnter

This is a 2D game:

``````||
||                `BC`
||             `Big  Cirle`
||     <--- `Big      Circle`
||              Big Circle`
||                `BC`
||
||
||
``````

So Imagine the ‘stick’ on the left is a network of 9 cubes all stuck together. The ‘Big Circle’ is a sphere collider. Essentially the big sphere collider is the range of an auto-gun. When the cubes are in range I want the auto-gun to take out the first one that comes in range and that one only.

I also want it to take about a second, which I think can be done with a simple yield statement. After that second I want the autogun to start firing on the next closest cube(not exactly sure which one that is yet)…maybe they’re already is an Algorithm for this.

Hey hijinx, that works great but for my purposes I was trying to do something a little different.

``````function OnTriggerEnter (other : Collider){
if (other.tag == "enemyCube"){
yield Fire(other.gameObject);
}
}

function Fire (cube : GameObject){
yield WaitForSeconds (1.0);
Destroy(cube);
}
``````

The pros of this : the cubes get destroyed in the order that they entered the ‘range’ of the collider(I want this to happen)

Cons: OnTriggerEnter is being called about every 10 milliseconds because of the speed of the Big Circle collider. So what ends up happening is the first cube is destroyed after the delay of 1 second and then all the other ones get destroyed almost instantly after that.

I want the collider to enter the cube network and destroy one cube per 1 second(for example). The order of cubes is important.