my scene isnt relaoding when i die

EDIT: NEVERMIND, I JUST DIDN’T SEE THAT I PUT TIME.TIMESCALE = 0 IN MY SCRIPT, SORRY

so when i die in my game, i have a death menu where if you play “play again”, it will reload the level, for some reason, when i try it, it doesnt work
i have a scene transition/level loader script
here it is

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

public class LevelLoader : MonoBehaviour
{
    public Animator transition;

    public float transitionTime = 1f;

    // Update is called once per frame
    void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            //LoadLevel("Maze1");
        }
    }

    public void LoadLevel(string levelToLoad)
    {
        StartCoroutine(LoadLevelCoroutine(levelToLoad));
    }

    public IEnumerator LoadLevelCoroutine(string levelName)
    {
        //Play animation
        Debug.Log("Begin load animation");
        transition.SetTrigger("Start");

        //Wait for animation to stop playing
        Debug.Log("Waiting");
        yield return new WaitForSeconds(transitionTime);
        Debug.Log("Done waiting");

        //Load scene
        Debug.Log("Loading scene");
        SceneManager.LoadScene(levelName);

    }
}

here is the play again button

and here is the level loader in inspector
7176517--860386--upload_2021-5-25_21-20-30.png

When you say it doesn’t work. What doesn’t work? Does the coroutine never start? Do you see all your debug messages? You have a lot in there, which is great for debugging, but you didn’t mention if they run or not.

In addition to what @Brathnann suggests above, check also that you have an EventSystem still in the scene when you need this interactivity.

everything works in the coroutine and it debugs “waiting” but it doesnt debug “done waiting” and change the scene
so its something wrong with the wait i think

the button press works so im pretty sure the event system is in the scene

AFAIK Coroutine will stop if MB or GameObject was disabled or destroyed. Maybe there is something wrong here?

2 Likes

Did you perhaps set Time.timeScale = 0 before here?

IF so, use unscaled waits…

EDIT: and also print out the time in seconds it will wait at the “WAiting” debug… why not?

what is mb?

i did not set time.timescale, i just disable player movement by setting a boolean to false, i cant use time.timescale or else scene transitions wont work

edit: actually nvm, i actually did set time.timescale to 0, i just didnt see it

1 Like

Remember the six stages of debugging:

  1. That can’t happen.
  2. That doesn’t happen on my machine.
  3. That shouldn’t happen.
  4. Why does that happen?
  5. Oh, I see. <— you are here
  6. How did that ever work?

thanks, but im confused on this process, what does #6 mean? is it asking how i didn’t notice it?

MonoBehaviour.

No, it’s specifically referring to your comment here:

This led you to think “oh it can’t be timescale because my scene transitions work fine,” and then you realize “oh it WAS timescale, and the scene transitions continued working fine anyway (for whatever reason).”

This type of “wait… how did this ever work?!” question comes up ALL THE TIME when you’re working with big systems. Stuff works and in your mind you think “Oh it is working because of X…” and then one day you notice that you never actually put X into your program at all, and suddenly you blink and think “Wait, what is making this work?!”

All the time. Happens ALL the time. We are all human and we are HORRIBLE at reasoning about stuff like this, and the computer is ultra stupid and just mindlessly does what it is told, and when it works we go “Cool, I fixed it!” when it was actually because something else changed.