- Home /
Way to pause/unpause, or stop/start mouselook script?
I wrote a script to pause the game when the esc key is hit. This includes the Time.timeScale being set to 0 when paused as well as AuidoListener.pause being set true when the key is hit, and the opposite values in order to unpause it. When it is paused however, I also want the character to stop being able to look around (which I figure disabling mouselook would take care of) So that my menu options when paused can be clicked on without the character looking around while the selection is trying to be made.
Answer by Apples_mmmmmmmm · May 04, 2011 at 01:59 AM
So after looking around, I was able to find somewhat of a solution. However, even with the following code, the player can still rotate around the x-axis which I've yet to find a solution to.
if(Input.GetKeyDown(KeyCode.Escape))
GetComponent("MouseLook").enabled = !GetComponent("MouseLook").enabled;
Answer by GesterX · May 03, 2011 at 11:14 PM
You need to disable the mouselook script with something similar to below (from a similar question):
Static var Dialog : Boolean = false;
Then put this inside your update function:
if(Dialog){ GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false; GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false; }
if(!Dialog){ GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = true; GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;
}
Then just toggle the Dialog variable when the game is paused and unpaused.
I tried adding this in and recieved errors because $$anonymous$$ouseLook is not static, how would I go about making this static?
Hmm, I tried a few variations of your code within my script and couldn't seem to get it to work still. If I have it as is, I get an error to put a ; after the static var line. If I change the line to static var Dialog : boolean = false; then the first error goes away, but I'm left with the errors for trying to access non static member GetComponent. Any more ideas?
Your answer

Follow this Question
Related Questions
Mouse look script help 1 Answer
MouseLook.cs:case of JavaScript 1 Answer
Showing and Locking Cursor - JavaScript / JS 1 Answer
Screen go Gray and only Cursor active OnTriggerEnter 1 Answer
Setting Scroll View Width GUILayout 1 Answer