- Home /
Quad does not restart position
I have a problem I am not sure how to resolve. I have a Quad with a very long image and a script that makes this whole thing into a scrolling background. The problem is that when my player dies and I restart the game, the quad does not start from the beginning of the image, but rather continue from the point of death. After a few deaths, my player spawns on an empty background, because the Quad image has long finished. I tried destroying it on player death, and it did get destroyed, but after a restart, it still remembered the last position the Quad reached. Any ideas how I can resolve this?
The scrolling code:
public class BG : MonoBehaviour {
float timer = 0;
bool timerReached = false;
const float TIMER_TIME = 45f;
public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
{
if (!timerReached)
{
timer += Time.deltaTime;
Vector2 offset = new Vector2(0, Time.time * speed);
GetComponent<Renderer>().material.mainTextureOffset = offset;
}
if (!timerReached && timer > TIMER_TIME)
{
timerReached = true;
}
}
}
}
Answer by Bunny83 · Mar 14, 2018 at 06:22 PM
You have a "timer" variable which you do not use at all and instead you currently use Time.time in your texture offset. Time.time won't reset unless you restart the whole appliation. I guess you wanted to use the timer variable instead? Don't forget the reset that timer whenever you want to reset the game.
Oh my god. It was that simple.
Yes, I did use the wrong variable.