issue with speeding up quad set on repeat

So i have a quad with shader set to cutout that acts as a foreground element on an endless runner game. the game is set to speed up after every 100 points which works fine but my quad gets reset every time i hit the points. like on 100 it flickers back to its starting position and speeds up as expected. any ideas how i can make it seamlessly? the code is not anything special to be honest just multiple if statements

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TextureScroll : MonoBehaviour
{
    Material backgroundMaterial;
    public float scrollSpeed;
    public bool scroll = true;
    private void Awake()
    {
        backgroundMaterial = GetComponent<Renderer>().material;
    }
    // Start is called before the first frame update
    void Update()
    {
       
        if (GameManager.score > 100)
        {
            scrollSpeed = 0.10f;
        }
        if (GameManager.score > 200)
        {
            scrollSpeed = 0.12f;
        }
        if (GameManager.score > 300)
        {
            scrollSpeed = 0.14f;
        }
        if (GameManager.score > 400)
        {
            scrollSpeed = 0.16f;
        }
        if (GameManager.score > 500)
        {
            scrollSpeed = 0.18f;
        }
        if (GameManager.score > 600)
        {
            scrollSpeed = 0.20f;
        }
       
    }

    private void FixedUpdate()
    {
        if (scroll)
            {
                Vector2 offset = new Vector2(scrollSpeed * Time.time,0);
                backgroundMaterial.mainTextureOffset = offset;
            }
    }
}

edit i can do it like this adding an acceleration variable for it to speed up over time but i am also trying to figure out how to do it with score too!

scrollSpeed += Time.deltaTime * acceleration;

I haven’t tried this to check, but it looks like the changing of the scrollSpeed variable will cause the offset to suddenly jump.

Would suggest making offset a class variable.
i.e. between lines 9 and 10 add:
Vector2 offset = Vector2.zero;

Then at line 42 add (this ensures the offset is continuously amended rather than suddenly jumping when scroll speed changes):
offset.x+=scrollSpeed*Time.deltaTime;

then remove line 49 as the offset has already been calculated.

1 Like