Unity timer with scenemanager

Asked

Viewed 48 times

0

Basically it’s the following: I have 2 codes, 1 that serves to reset the level when I throw the ball:

public Player player;
public float resetTimer = 5f;

void Update () {
        if (player.holdingBall == false) {
            resetTimer -= Time.deltaTime;
            if (resetTimer <= 0) {
                SceneManager.LoadScene ("Game");
            }

And this one right here is a timer that goes to an end game screen

void Start () 
 {
  timerSeconds = GetComponent<Text> ();
 }
 
 // Update is called once per frame
 void Update () 
 {
  timer -= Time.deltaTime;
  timerSeconds.text = timer.ToString("f0");
  if (timer <= 0) 
  {
   Application.LoadLevel (LevelToLoad);
  }
 }

The problem is this: when I throw the ball after 5 seconds the level reset but the timer also returns to 30 and did not want you to turn around. How do I do it? I should have put the two together or...

1 answer

0

Just make the timer you don’t want to re-set a Static

public static float timer = 30;

It will no longer appear in the inspector at Unity, but it will work as you ask. When you want to reset it, just give it a new value through code, like timer = 30;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.