Basically what i am trying to do is when the instantiated projectile hits the enemy i want the enemy to be destroyed. But instead if i shoot one enemy a different one gets destroyed or multiple ones get destroyed.
also if anyone could help me with giving the enemy life so it would take 10 projectile to kill one enemy id greatly appreciate it.
the below script is attached to the prefab projectile.
thanks
#pragma strict
var speed = 80.0; Speed of Bullet
var time = 0.0; time bullet remains in world
function Update ()
{
time += Time.deltaTime;
transform.Translate(Vector3.forward * speed * Time.deltaTime, Space.Self); // Move translation along the object’s z-axis
if(time > 2) if the bullet remains in the world longer then 2 seconds
{
Destroy(gameObject); destroys bullet after 2 seconds
}
}
function OnCollisionEnter(projectileCollision : Collision)
{
Destroy(gameObject); destroys bullet when the bullet collides with any game object
if (projectileCollision.gameObject.name == "Enemy") if the bullet collides with enemy
{
Destroy(gameObject.Find("Enemy"));
}
}
thank you so much!!! that worked