I need a turret script

ok im doing the worm game tutorial (tornado twins) and I cant get the turret script to work, ive got it to fire in intervals, but it just does a masive spay for one second and has a rest for the next. heres my code: (ps I would apreciate it if somone would post there turret code so that way i dont have to mess around, i think below is enough to say I have tried my hardest. oh lol, ive just realised it cuts it off, http://www.youtube.com/watch?v=raNfTotAGQw thats a screen video i did of my problem with the code in the botum bar, thanks

var LookAtTarget : Transform;
var damp : float = 6.0;
var bullitPrefab : Transform;
var savedTime = 0;

function Update ()
{
     if(LookAtTarget)
     {
          var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); 
          transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp); 
          var seconds : int = Time.time;
          var oddeven = (seconds % 2);
          if(oddeven) 
              Shoot(seconds);
          //transform.LookAt(LookAtTarget);
     }

}

function Shoot(seconds)
{
     if(seconds!=savedTime)
     {
          var bullit = Instantiate(bullitPrefab ,transform.Find("spawnPoint").transform.position , Quaternion.identity); bullit.rigidbody.Addforce(transform.forward * 1000); savedTime=seconds;
     }
}

I think your code looks OK but I noticed there was an error in the log when you opened Unity so maybe there is a compile error with your code. If there is an error Unity will use the old version of the code, so make sure there are no errors in that Console. You can jump to the error by double-clicking it the console.

I have watched the this tutorial, but I didn't make the game. While I did learn quite a lot, I think their code is quite poorly written. Here is a clearer version of that code:

var LookAtTarget : Transform;
var damp : float = 6.0;
var bulletPrefab : Transform;
var nextShotTime : float = 0.0;
var timeBetweenShots : float = 2.0;

function Update()
{
     if(LookAtTarget)
     {
          var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); 
          transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);

          if (nextShotTime <= Time.time)
          {
              Shoot();
              nextShotTime = Time.time + timeBetweenShots;
          }
     }

}

function Shoot()
{
    var bullet = Instantiate(bulletPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
    bullet.rigidbody.Addforce(transform.forward * 1000);
}

I think I found your problem... below the modified code (just one var missplaced :p)

var LookAtTarget : Transform;
var damp : float = 6.0;
var bullitPrefab : Transform;
var savedTime = 0;

function Update ()
{
     if(LookAtTarget)
     {
          var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); 
          transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp); 
          var seconds : int = Time.time;
          var oddeven = (seconds % 2);
          if(oddeven) 
              Shoot(seconds);
          //transform.LookAt(LookAtTarget);
     }

}

function Shoot(seconds)
{
     if(seconds!=savedTime)
     {
          var bullit = instantiate(bullitPrefab,transform.Find("spawnPoint").transform.position , Quaternion.identity);
          bullit.rigidbody.Addforce(transform.forward * 1000); // Put this -> savedTime=seconds;
     }

     //here
     savedTime=seconds;

}

Let me know if it worked ;)

There's a decent turret solution in one of my iTween examples: http://itween.pixelplacement.com/examples.php

I’ve got a problem aswell i copied and pasted petroz’s script but this was the error that it came up with 359 times

NullReferenceException
TurretControl.Shoot () (at Assets/TurretControl.js:25)
TurretControl.Update () (at Assets/TurretControl.js:18)

please help me