I have a typical parallax backgrounds. They are scrolling by

public float Speed=0f;

void Update () 
    renderer.material.mainTextureOffset = new Vector2 (Time.time*Speed,0);

I have a character. OnKeyDown he starts to move: Speed of background sets to 0.4f for example. OnKeyUp a character stops by setting the speed of background 0f. The problem is: when backgrounds stop to scroll, they return to its start position. They must just to pause the position. How to do?


You should use delta time instead of total time. And keep the "running total" in your offset variable, instead of in time.

renderer.material.mainTextureOffset += new Vector2 (Time.detlaTime*Speed,0);

Then, when you come back from a pause, the mainTextureOffset is where you left it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.