SetTextureOffset, small offset skip?

I’m using a small SetTextureOffset script to make my background pan and repeat itself. It works perfectly, but when I call the script it skips a little offset. This is the script I’m using:

var actualSpeed : float;
private var scrollSpeed : float;
private var script : PlayerScript;
function Start () {
		scrollSpeed = 0;
		script = GameObject.FindObjectOfType(PlayerScript);
}

function Update () {
	if(script.Fired){
	scrollSpeed = actualSpeed; 
	var offset = Time.time * scrollSpeed;
    renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
    }
   	if(script.rigidbody.IsSleeping() && script.Fired){
	    scrollSpeed = 0;
	}
}

Anyone any suggestions?

Sorry for the Necromancy and I’m sure you’ve already solved this, but I’m tracking down a jitter in my scrolling background and found this. So maybe it will help someone else.

Your problem is you’re using Time.time which is how much time has elapsed since the start of the program. So if you call Start() 10 seconds in to your program running, it jumps from 0 offset to 10 seconds worth of offset. If you stop the animation for 3 seconds, and start it back up, it will skip 3 seconds worth.

Instead, you can use Time.deltaTime and keep up with the offset between this frame and last frame. You’ll also have to keep up with your total offset and use that.

private float offset = 0;


function Update()
{
    if(script.Fired)
    {
        scrollSpeed = actualSpeed;
        offset += Time.deltaTime * scrollspeed;
        renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
    }
}