Hard coded shooting offset sometimes randomly changes (why?)

Hello!

Short story; I have coded an offset into some turrets but they don’t stick to the offset - they sometimes randomly change and I’ve no idea why!

Long story;

I have the following code which shoots a bullet every 2 seconds. And then shoots the next bullet in the array.

When they hit certain colliders they reset to the initial position and velocity (stationery).

(In case you’re wondering why I haven’t simply instantiated and destroyed them it’s because that takes a lot of processing power on iOS).

    var sodBullets : Rigidbody[];
    var bulletForce : float;
    var shootInterval : float = 2;
    var offset : float;
    var lastShot : float = 0;
    var bulletIndex = 0;

    function Update()
    {
    	if (Time.timeSinceLevelLoad + offset > lastShot + shootInterval) 
    	{
    		sodBullets[bulletIndex].rigidbody.velocity = transform.TransformDirection(Vector3(0,0,bulletForce));
    		lastShot = Time.timeSinceLevelLoad + offset;
    		bulletIndex++;
    		if (bulletIndex > (sodBullets.length-1))
    		{
    			bulletIndex = 0;
    		}
    	}
    }

I have several of these turrets shooting with a slightly different offset to one another. For example the first is at 0 seconds offset, the second is at 0.5, the third at 1.0 and the fourth at 1.5 therefore they should hopefully all shoot one after another every half a second. But a bullet will only come out of the same turret every two seconds. Hopefully that made sense!

The problem is that this works for a few times at first and then after playing for a little while (not sure how long as it’s always different) they start shooting at different offsets which appears to have been changed randomly.

Any ideas?

Unity Answers post on same question; http://answers.unity3d.com/questions/133819/turret-shooting-sometimes-changes-offset-why.html?viewedQuestions=133815&viewedQuestions=25537

I think

lastShot = Time.timeSinceLevelLoad + offset;

should be

lastShot = Time.timeSinceLevelLoad;

Thanks for the reply Moonjump.

The problem has been sorted in the related Unity answers thread;
http://answers.unity3d.com/questions/133819/turret-shooting-sometimes-changes-offset-why.html?viewedQuestions=133815&viewedQuestions=25537