- Home /
Main Camera = false problems
For my pause script i wanted the camera to freeze, unlock, and then freeze again when paused. It starts out okay but it never changes to true.
private var lock_X : boolean = true;
private var lock_Y : boolean = true;
function Start() {
lock_X = GameObject.Find("First Person Controller").GetCompenent(MouseLook).enabled = false;
lock_Y = GameObject.Find("Main Camera").GetCompenent(MouseLook).enabled = false;
}
function Update(){
lock_X = lock_X
lock_Y = lock_Y
}
function PauseGame(){
lock_X = !lock_X;
lock_Y = !lock_Y;
}
function UnPauseGame(){
lock_X = !lock_X;
lock_Y = !lock_Y;
}
Answer by perchik · Apr 11, 2014 at 06:02 PM
Well here's a few thoughts
It's probably a bad idea to toggle the locks, when you know what you want them to be. When you unpause you want to set lock_X = false, so do that. Toggling it could lead to incorrect behavior.
Second, lock_X = lock_X
does nothing.
Next, this line lock_X = GameObject.Find("First Person Controller").GetCompenent(MouseLook).enabled = false;
probably doesn't do what you expect. It sets lock_x
and the enabled member of the mouse look component to false. My guess is that you want to save the current value of enabled and then toggle it later.
Then, you're not actually changing .enabled
after Start because Lock_X copies the value of enabled, but doesn't actually point to enabled. So changing Lock_X doesn't changed the enabled property
With all that said, Here's some untested code that I think may work:
private var lock_X : boolean = false;
private var lock_Y : boolean = false;
private var fpsMouse : MouseLook;
private var camMouse :MouseLook;
function Start()
{
fpsMouse = GameObject.Find("First Person Controller").GetCompenent(MouseLook);
camMouse = GameObject.Find("Main Camera").GetCompenent(MouseLook);
fpsMouse.enabled = false;
camMouse.enabled = false;
}
function Update()
{
if(fpsMouse.enabled != lock_X)
{
fpsMouse.enabled = lock_X;
}
if(camMouse.enabled != lock_Y)
{
camMouse.enabled = lock_Y;
}
}
function PauseGame()
{
lock_X = false;
lock_Y = false;
}
function UnPauseGame()
{
lock_X = true;
lock_Y = true;
}
Still, with all that said, you never call PauseGame() or UnpauseGame() in this code, so I don't know if it ever gets called.
EDIT Updated the code to include lock_Y.
Your answer
Follow this Question
Related Questions
OnTriggerStay Not Working, JavaScript Help Needed 1 Answer
Animation Script not working. 1 Answer
fps MouseLook with animation applied to camera. 1 Answer
Mouse look script help 1 Answer