unity to determine the number of collisions

I want to make enemies enemy encounter objects Player, when the enemy to enemy collision objects Player three times, the object is converted to an object thing Player

Will the program how to write?

**var thing ;
function OnCollisionEnter(theCollision : Collision){
    if(theCollision.gameObject.name == "enemy"){

 Destroy(gameObject);
 Instantiate(thing,transform.position,transform.rotation);

    } else if(theCollision.gameObject.name == "PC"){
         Debug.Log("Nothing");
        }
}**

1 Answer

1

you could try something like this...

var thing;

function OnCollisionEnter(theCollision : Collision){    
     var clone = Instantiate(thing,transform.position,transform.rotation);
     Physics.IgnoreCollision(clone.collider, collider);
     Destroy(gameObject); 
} else if(theCollision.gameObject.name == "PC"){
     Debug.Log("Nothing");
}

what your issue could have been is that you distroyed the GameObject before you instantiated the "thing" object.