- Home /
Question by
sacajawhoohoo · Sep 12, 2013 at 11:05 PM ·
errorcontinue
Contunuing from old scene
Here is my script:
DontDestroyOnLoad(gameObject);
function Update()
{
if(Input.GetKey("escape"))
{
Application.LoadLevel("Pause menu");
}
}
My problem is when loading a new scene it just creates a new first person controller and restarts me instead of continuing from the original. and it keeps doing this every time i reload the pause menu until it lags like crazy. so how do i destroy the old one and only use the one that isnt destroyed?
Comment
Answer by voncarp · Sep 13, 2013 at 04:04 AM
Add this C# script to that gameobject and get rid of the DontDestroyOnLoad(gameObject);
using UnityEngine;
using System.Collections;
public class DontDestroyScript : MonoBehaviour {
public static bool created = false;
void Awake() {
if (!created) {
DontDestroyOnLoad(this.gameObject);
created = true;
}
else {
Destroy(this.gameObject);
}
}
}
Someone else made a script like this on here that I referenced. Should work.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Script is not working at all 2 Answers
Reverting to Menu screen after game over 1 Answer
Unexpected Token 3 Answers