Multiple Objects spawning OnCollisionEnter

Hello All,

I have a box that when hit with a bullet, 3 times it will Instantiate an object a coin.

The problem Im having is that when multiple bullets hit it will Instantiate more than one prefab and I not sure how to fix it? For example a single bullet no problem, but 3 bullets side by side all collide at the same time then more than one coin is Instantiated. Any suggestion?

var hitPoints : int = 3;
var cashPrefab : Transform;
var isThereCash : boolean = false;

function OnCollisionEnter(hit : Collision) 
{
	if(hit.gameObject.name == "iBullet")
	{
    	hitPoints -=1;
    	}
	
			   
    if(hitPoints < 1)
    {
    	if(isThereCash)
    	{
    		Instantiate(cashPrefab, transform.position, transform.rotation);
    		
      	}
		// Destroy the box
    	Destroy (gameObject);
    }
}

Ok I figured it out :slight_smile: Instead of less than 1 I did equals zero :slight_smile:

if(hitPoints == 0)
    {
    	if(isThereCash)
    	{
    		Instantiate(cashPrefab, transform.position, transform.rotation);
    		
      	}
		// Destroy the orangebox
    	Destroy (gameObject);
    }