- Home /
Pause game camera movement s
Hi all! I have a very simple problem and I'm not asking for code. I have a pause game script (below) and I have a tiny issue. Everything stops, but the player can move the mouse look camera around while paused. Is there any way I can lock the mouse look script while paused?
var paused : boolean = false;
function Update () {
if(Input.GetKeyDown(KeyCode.P)){
if(!paused){
Time.timeScale = 0;
paused=true;
}else{
Time.timeScale = 1;
paused=false;
}
}
}
Untested suggestion: Just add the following line to the top of Update() in the mouse look script.
if (Time.timeScale < 0.01) return;
Answer by Commander Quackers · Nov 27, 2013 at 03:56 AM
Here's my solution, works fine for me.
var paused : boolean = false;
function Update () {
if (Input.GetButtonDown("Escape"))
GetComponent(MouseLook).enabled = false;
else if (Input.GetButtonUp("Escape"))
GetComponent(MouseLook).enabled = true;
if(Input.GetKeyDown(KeyCode.Escape)){
if(!paused){
Time.timeScale = 0;
paused=true;
}else{
Time.timeScale = 1;
paused=false;
}
}
}
This is good, but you have to hold down P to have it locked.
Out of your code I made this: var paused : boolean = false; function Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.P)){ if(!paused){ Time.timeScale = 0; paused=true; GetComponent($$anonymous$$ouseLook).enabled = false; }else{ Time.timeScale = 1; paused=false; GetComponent($$anonymous$$ouseLook).enabled = true; } } }
So if your press P it toggles it. Thanks for your help!