0n35
October 31, 2012, 9:20pm
1
My current code isn’t working and I’m not sure why.
When I press the escape key, I want it to stop the script (MouseLook) and restart it when I press escape again, why isn’t this working?
var FreezeScreen : boolean = false;
function CheckFreeze () {
if(Input.GetKeyDown(KeyCode.Escape)) {
FreezeScreen = !FreezeScreen;
}
if(FreezeScreen == true) {
GetComponent(MouseLook).enabled = false;
}
if(FreezeScreen == false) {
GetComponent(MouseLook).enabled = true;
}
}
What exactly is going wrong with this code?
Is it throwing an exception?
Just doing nothing?
Is CheckFreeze() called from an Update method?
Is this script attached to an object that also has a MouseLook component?
0n35
November 3, 2012, 4:50am
4
The last one is true, and what’s happening is it isn’t freezing anything, I’m not sure what I need to do…
CheckFreeze() needs to be called from an Update function somewhere or just change the name of CheckFreeze to Update.
Time.timeScale = 0; its gonna freeze everything and if Time.timeScale = 1.0 then everything will be normal
0n35
November 4, 2012, 12:59am
7
This will have multiple people in game though, what you said would freeze it for everyone correct?
0n35
November 4, 2012, 2:13am
8
I might just be stupid, but this isn’t working…my code now:
var FreezeScreen : boolean = false;
function Update () {
if(Input.GetKeyDown(KeyCode.Escape)) {
FreezeScreen = !FreezeScreen;
}
}
function CheckFreeze () {
if(FreezeScreen == true) {
GetComponent(MouseLook).enabled = false;
}
if(FreezeScreen == false) {
GetComponent(MouseLook).enabled = true;
}
}
Democre
November 5, 2012, 10:13pm
11
still doing nothing? Is this on a webplayer? If so, the escape key is a little funky there.
This link could get you to where you want to be.
0n35
November 6, 2012, 1:01am
12
This helped a lot, thank you.