- Home /
How can I pause the "Mouse Look" script when I pause my game?
Im trying to create a 'pause-game' button, so far I've managed to pause the game and sound. But Im having trouble pausing the camera (Mouse Look Script), is there something I have not added to the script? Appreciate any help.
var pausedGUI : GUIText; pausedGUI.enabled = false;
static var pauseVisible : boolean; private var player : GameObject; private var cam : GameObject;
function Start() {
// initially hide the pause menu
pauseVisible = false;
player = GameObject.Find("First Person Controller");
cam = GameObject.Find("Main Camera");
}
function Update () { if(Input.GetKeyUp("p")){ if(paused == true){ paused = false; } else { paused = true; }
if(paused == true){ Time.timeScale = 0.0; pausedGUI.enabled = true; } else { Time.timeScale = 1.0; pausedGUI.enabled = false; }
if(paused == true){
AudioListener.pause = true;
} else {
AudioListener.pause = false;
}
if(paused == true){
GetComponent("MouseLook").enabled = true;
} else {
GetComponent("MouseLook").enabled = false;
}
}
}
Answer by Justin 3 · May 10, 2011 at 03:36 AM
I heavily modified the pause menu script found on the Unity wiki for my own game. I pasted below a link to the code I used (in JavaScript).
I also posted this on the most popular pause game question thread, but I doubt anyone will ever consider looking at it since the question already has 11 answers. Look at the UnPauseGame and PauseGame functions for how to solve the MouseLook problem, but if you want you can just use the whole script.
Thank you so much...the problem is finally solved. Definately a great script for helping first time game devs.