Event when the scene is loaded
I have an object that is not destroyed when loading new level. I need to be at each load level executed block of code, I've seen lots of solutions but everything seems to be outdated. Earlier I used (see. Code block), but now it does not work.
if(Application.loadedLevelName != "Menu"){
//Hide loading screen, in menu do it in different script.
}
can anyone advise me how to do it ?
ps. I apologize for any errors in the text, Czech, I am not very good in English
Answer by corn · Jan 08, 2017 at 10:58 AM
What version of Unity are you using ? If it's below 5.4, you need to use MonoBehaviour.OnLevelWasLoaded. If it's 5.4 or above, you're looking for SceneManager.sceneLoaded.
Here is a detailed answer explaining how to use the sceneLoaded
event.
This is exactly the type of solution I am looking for when wanting to reset any level and gathering all the other missing links, such as the UI elements or any object present, but the original references are destroyed.
Your answer
Follow this Question
Related Questions
Switching between a VR and non VR scene 1 Answer
How to make a main menu like that ? 1 Answer
Why is my scene not loading? 2 Answers
Save and load scene from file 2 Answers