Hi i got a script :
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.name == "zombie")
{
Destroy(collision.gameObject);
}
}
Its a nice script, but i want it delete object when two object collide ( its like enemy healt ) like when i shoot two time it delete it, thanks !
The easiest way would probably be to make a new script for you enemies and attach it to them instead of the bullet. You could do something like this:
var enemyHealth = 2;
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.name == "bullet")
{
enemyHealth -= 1;
if (enemyHealth <= 0)
{
Destroy(this.gameObject);
}
}
}
However, it would probably be a better idea to give your bullets a tag, like “bullet”. The code would be almost exactly the same, but instead of collision.gameObject.name it would be:
if (collision.gameObject.tag == "bullet")