Quantcast
Channel: Latest Questions by Ben_the_Lad
Viewing all articles
Browse latest Browse all 8

Pause Script Suddenly Stops Working

$
0
0
Hello, I had a simple pause script (adapted from [this tutorial][1]) that I built last night. It worked very well and was 100% reliable. Tonight, it seems to have broken, though I've made no changes to the script (or any other script, for that matter). The script is here: #pragma strict private var pauseGame : boolean = false; private var showGUI : boolean = false; function Update() { if(Input.GetButtonDown("Pause")) { pauseGame = !pauseGame; if(pauseGame == true) { Time.timeScale = 0; pauseGame = true; (GameObject.Find("Main Camera").GetComponent("MouseLook") as MonoBehaviour).enabled = false; (GameObject.Find("First Person Controller").GetComponent("MouseLook") as MonoBehaviour).enabled = false; showGUI = true; } } if(pauseGame == false) { Time.timeScale = 1; pauseGame = false; (GameObject.Find("Main Camera").GetComponent("MouseLook") as MonoBehaviour).enabled = true; (GameObject.Find("First Person Controller").GetComponent("MouseLook") as MonoBehaviour).enabled = true; showGUI = false; } if(showGUI == true) { (gameObject.Find("PausedText").GetComponent("Text") as MonoBehaviour).enabled = true; (gameObject.Find("PausedImage").GetComponent("Image") as MonoBehaviour).enabled = true; (gameObject.Find("Crosshair").GetComponent("Image") as MonoBehaviour).enabled = false; (GameObject.Find("Main Camera").GetComponent("Blur") as MonoBehaviour).enabled = true; } else { (gameObject.Find("PausedText").GetComponent("Text") as MonoBehaviour).enabled = false; (gameObject.Find("PausedImage").GetComponent("Image") as MonoBehaviour).enabled = false; (gameObject.Find("Crosshair").GetComponent("Image") as MonoBehaviour).enabled = true; (GameObject.Find("Main Camera").GetComponent("Blur") as MonoBehaviour).enabled = false; } } Now, when I run the game, timeScale goes to 0, but the other functions (disabling MouseLook and toggling the GUI stuff) do not work. However, if I turn on my PauseGUI by default, it will render (even though it should not per this script) and turn off the first time Escape is tapped, then be unresponsive. I get this error in the console: NullReferenceException: Object reference not set to an instance of an object Pause.Update () (at Assets/Scripts/Pause.js:26) The only thing that changed was that I downloaded and imported the Survival Shooter demo, played with it for a few minutes, then deleted it when I discovered how badly it mucked up my folder structure. I did not delete any of the files that this one interacts with (Mouselook and blur are still there) nor did I alter the shape of my prefab. So... does anyone have any thoughts? Cause I'm at a loss. :D [1]: https://www.youtube.com/watch?v=tdU9ujYMA_k

Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images