- Home /
Dont destroy on load not working
Alright so I have my main scene set up, and when I leave to a new scene I want to be able to come back to the old one with my character controller still in the last place is was, here is my current script:
function Update()
{
if(Input.GetKey("escape"))
{
Application.LoadLevel("Pause menu");
}
}
This is the script I tried and had numerous errors with:
function Update()
{
if(Input.GetKey("escape"))
{
Application.LoadLevel("Pause menu");
Application.DontDestroyOnLoad("First Person Controller");
}
}
I'm sure it is a simple error on my part, but I am not huge into coding, the only thing I could think of was that I would need to have a new function Update() But if anyone could help, that would be great!
Answer by yannru.cheng · Aug 28, 2013 at 05:00 AM
That's not how Don'tDestroyOnLoad works. Don'tDestroyOnLoad is used to keep the target object not be destroyed when loading a new scene. This means that your character controller will not be destroyed will you move from main scene to new scene.
take a look at the documentation http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
You want to call the function in Awake() not Update
Your answer
Follow this Question
Related Questions
,SUCCEDED(HR) Error 0 Answers
DontDestroyOnLoad make errors 0 Answers
Unity Compiler Error Glitched. 0 Answers
URP Baked lighting makes the colour blue turn black 0 Answers
A* Pathfinding 0 Answers