Hello!
I’m working on a side scrolling game in which the road and few layers of background have scrolling texture to make the ilusion of movement along x axis.
Here is the script I made for this:
void Update () {
float newX = myRenderer.material.GetTextureOffset ("_MainTex").x + step;
float newY = myRenderer.material.GetTextureOffset ("_MainTex").y + step;
Vector2 newOffset = Vector2.Lerp (myRenderer.material.GetTextureOffset ("_MainTex"), new Vector2 (newX, newY), Time.deltaTime * speed * GameManager.Instance.globalScrollSpeed);
myRenderer.material.SetTextureOffset ("_MainTex", newOffset);
}
And this works perfectly for about a minute or so, but after that, the texture begins staggering. I think because the value of the texture offset is constantly increasing and reaches really high values.
I used something like this to fix it, but it made it worse:
if (newX > 1)
newX -= 1;
if (newY > 1)
newY -= 1;
Anyone has an ideea how to fix for this?