- Home /
How to Restart Level ?
Hello peeps! I have a problem, before the script goes, it would give restart level when it hit an object. I've made some changes and now it's not working the same way. I added tags to objects but I do not know what to do.
private void OnTriggerEnter2D(Collider2D Respawn)
{
if (Respawn.tag.Equals("Respawn"))
{
StartCoroutine("ReloadScene");
Time.timeScale = 0f;
}
IEnumerator ReloadScene()
{
yield return new WaitForSecondsRealtime(0.5f);
SceneManager.LoadScene("SampleScene");
}
}
Good day. Explain, be specifyc and clear, what you have, what you get, what you want...
Did you wrote this code?
Why are you doing this?
Time.timeScale = 0f;
You know what it does? you are stopping internal time... Its to "stop the game" while loading ?
Where is the problem then? what is not working? what you get? what you want to get?
OR give more infor or we can not help you...
Hi @tormentoarmagedoom , I did not write the code, I looked at youtube in the tutorial. So, before the main object was to say "the player" was hitting the obstacle, the game was over. Now the player gets hit by the object, nothing happens, it just gets stuck in the object. I want to resume the scene when the player hits the object. Excuse but I use google translations to express myself better.
Answer by terchilaionutgeorge · Feb 28, 2019 at 07:52 AM
SOLVED
private void OnTriggerEnter2D(Collider2D Player)
{
if (Player.tag.Equals("Respawn"))
StartCoroutine("ReloadScene");
Time.timeScale = 0f;
}
IEnumerator ReloadScene()
{
yield return new WaitForSecondsRealtime(0.5f);
SceneManager.LoadScene("SampleScene");
}
No need to be using a coroutine, just call the method using Unity's Invoke and handle everything within one method.
Invoke("ReloadScene", 0.5);
Answer by hydrox1 · Feb 27, 2019 at 10:10 AM
Hi, this should fix it : Application.LoadLevel(Application.loadedlevel);
just replace this with the SceneManager...
and i get this in console: Coroutine 'ReloadScene' couldn't be started! UnityEngine.$$anonymous$$onoBehaviour:StartCoroutine(String)
Answer by deus0 · Jun 30, 2021 at 09:34 AM
I believe its something like:
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
Your answer
Follow this Question
Related Questions
My game keeps restarting at random 1 Answer
How do I restart games with more than one level 1 Answer
How reset the Position of all puzzle pieces? 1 Answer
Car Game For School Project 2 Answers