What am I doing wrong?! (414671)

hey guys! I’ve got a bit of a problem… Im trying to make a Turret that follow the Players movement and shoot him. But when the buttes hit a wall or the player I want the bullet to destroy. When the bullet has bin destroyed the prefab is missing and it wont shoot anymore…

This is the script I use for the Turret:

var Bullet: Rigidbody;
var Timer = 0;
var Player: Transform;

function Update ()
{
transform.LookAt (Player);
Timer ++;

if(Timer > 150)
{
Timer = 0;
Bullet = Instantiate(Bullet, transform.position, transform.rotation);
Bullet.velocity = transform.TransformDirection (Vector3.forward * 25);
}
}

And this is the script I use for the Bullets:

function OnTriggerEnter(otherObject: Collider)
{
if(otherObject.gameObject.tag == “Wall”)
{
Destroy(gameObject);
}

if(otherObject.gameObject.tag == “Player”)
{
Destroy(gameObject);
}
}

What am I doing wrong? And if you know any good scripts for this or any good tutorials please share :slight_smile: Thanks!

you are overwriting the original bullet with a copy and deleting it later. try this

var bulletClone = Instantiate(Bullet, transform.position, transform.rotation);
bulletClone.velocity = transform.TransformDirection (Vector3.forward * 25);

Works grate! thanks!