Lock camera when paused

When I pause my game I want the player camera to freeze, so when I move the cursor around to chose a menu option, the inGame camera doesn’t move around. Here’s my pause script. I added some code to try and fix this, and it looks right to me, but it doesn’t work. I’d love some help with this problem. Tnx in advance

var paused : boolean = false;
var myCheck : boolean = false;

function Start(){
   paused=false;
}


function Update () {
	if(Input.GetButtonDown( "Pause" ) ) {
	if(!paused) {
	Time.timeScale = 0;
	paused = true;
Screen.lockCursor = false;
	firstPersonControllerCamera = gameObject.Find("First Person Controller").GetComponent("MouseLook");
	mainCamera = gameObject.Find("Main Camera").GetComponent("MouseLook");
	firstPersonControllerCamera.enabled = false;
	mainCamera.enabled = false;
	

	}else{
	Time.timeScale = 1;
	paused = false;
	
Screen.lockCursor = true;
	firstPersonControllerCamera.enabled = true;
	mainCamera.enabled = true;
	

		}
	}
}

function OnGUI() {
	if( paused ) {
	
 if(GUI.Button (Rect ( 500, 90, 100, 30), "Restart" )) { 
    Time.timeScale = 1.0f;
    Application.LoadLevel( "stage2" );
	}

	if(GUI.Button (Rect ( 500, 130, 100, 30), "Options" )) {
	
	}
	
	if(GUI.Button (Rect ( 500, 170, 100, 30), "Quit" )) {
		}
	}
}

To start with put at the top of the file:

 #pragma strict

When you do that you will find that your code will not compile. The first problem is that you don’t declare ‘firstPersonControllerCamera’ and ‘main’ camera. The second problem is that you use the string version of GetComponent(). The string version returns an object of type ‘Component’, which does not have an enabled flag. You need to use the non-string version. Change lines 15 and 16 to the following:

var firstPersonControllerCamera = gameObject.Find("First Person Controller").GetComponent(MouseLook);
var mainCamera = gameObject.Find("Main Camera").GetComponent(MouseLook);

With the needed additions mentioned above it indeed works just fine :slight_smile:

(additions: FPS and main camera var )