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;