turret AI question

hey everyone!
so… I’m having a problem… I’m making a game of batleships, and i is going very well so far, but now I wanted to make an enemy shoot at me, so i’ve already make the boat look at me but now i cant make it shoot! this is my script can anyone tell me what is wrong with it?

var bullitprefab: Transform;

shoot();

function shoot(){

var bullit = Instantiate(bullitprefab, transform.Find("SpanwPoint").transform.position, Quaternion.Identity);



bullit.Rigidbody.AddForce(transform.right * 1000);

}

this should be this be enought, right?

I’m kind of a newbie in scripting… i’ve created my function, one called Shoot.right?

Well nothing is really wrong with it but the variable bullitprefab has to be rigidbody. Let me give you an example on how I would use this, and explain some stuff:

var bulletprefab : Rigidbody;//has to be rigidbody to fire, and made it "bullet" instead of "bullit"
var spawn : Transform;

function Update(){

if(Vector3.Distance(transform.position, Transform.Find("Player")) < 10){   
//if the distance between player and enemy is beneath 10 do the following:

shoot();
}
}

function shoot(){

 var bullet = Instantiate(bulletprefab, spawn.position, transform.rotation);

bullet.rigidbody.AddForce(transform.right * 1000); // had to be rigidbody notRigidbody

}

hey, thanks for your availability! I now have some errors like:

[1004-Unity+erros.png|1004]

can you “inlightme” one more time? plz