Turret that shots a raycast to detect my character then shots at him.

Hello everyone im New to UnityAnswers and im glad i found this place because i need some help with a few Javascripts. I'm pretty new to Scripting so i will explain the best i can.

WHAT I WANT TO HAPPEN: I created a Turret that i want to use a raycast to look for my Character. When it spots my Character i want the Turret to shot me EVEN IF i walk around it. I also want the Turret to stop shooting at me when i leave its raycast or walk behind a wall.

WHAT IS HAPPENING: When i enter the Turrets raycast it does see me, and it looks at me. But it doesnt shot at me and it still detects me through walls.

Heres my script im trying to use PLEASE HELP

var area:int =100; var target: Transform; var damp = 6.0; var bullitPrefab : Transform; var savedTime=0; var AttackSpeed=1000; function Update (){ var layermask= 1 << 8;

 var left = (transform.TransformDirection (-Vector3.right));
 var right = (transform.TransformDirection (Vector3.right));
 var up = (transform.TransformDirection (Vector3.forward));
 var down = (transform.TransformDirection (-Vector3.forward));

 if (Physics.Raycast(transform.position,left,area,layermask)){
 transform.LookAt( target );
 Debug.DrawLine(transform.position,target.position, Color.red);
 return;
 }

 if (Physics.Raycast(transform.position,right,area,layermask)){
 transform.LookAt( target );
 Debug.DrawLine(transform.position,target.position, Color.green);
 return;
 }

 if (Physics.Raycast(transform.position,up,area,layermask)){
 transform.LookAt( target );
 Debug.DrawLine(transform.position,target.position, Color.blue);
 return;
 }

  if (Physics.Raycast(transform.position,down,area,layermask)){
 transform.LookAt( target );
 Debug.DrawLine(transform.position,target.position, Color.yellow);
 return;
 }
 }

 if(target)
 {

 var seconds : int = Time.time;
 var oddeven = (seconds % 2);

 if(oddeven)
 {
 shoot(seconds);
 }

}

function shoot(seconds) { if(seconds!=savedTime) {

var bullit = Instantiate(bullitPrefab ,transform.Find("spawnPointA").transform.position , Quaternion.identity);

 bullit.gameObject.tag = "enemyProjectile";
bullit.rigidbody.AddForce(transform.forward * AttackSpeed);

savedTime=seconds;

}

}

You don't have a function, to start with... And, just a personal thing, its a little unorganized... But thats not important. If I were you I would add "function Update () {" to the top, and see what it does.


-Hope I helped

-Gibson