disable mouse look and weapon

ok so i have a code door and when i walk up to the door a gui code panel appears for me to enter the code to unlock it but the camera keeps moving along with the mouse and when i click the open button my gun fires. Here is what i have so far, the mouse just doesn’t stop.

var isCamPaused : boolean ;

function OnTriggerEnter(collision: Collider){

isCamPaused = true;

}

function OnTriggerExit(collision: Collider){

isCamPaused = false;

}

function Awake(){

if(isCamPaused){
        isCamPaused = true;
        GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false;

        GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false;
        }

}

Here is a fix for your problem Mate, There was one major thing you where doing wrong you where saying OnTriggerEnter But you where not saying what you collide with to set the trigger

var isCamPaused : boolean = false;

function Awake()

{

isCamPaused = false;

if(isCamPaused == true)

	{

		gameObject.Find("FirstPersonController").GetComponent("MouseLook")

.enabled = false;

	}

}

function OnTriggerEnter(hit : Collider)

{

if(hit.GameObject.name == "YourTrigger")

{

	isCamPaused = true;

}

}

function OnTriggerExit(unhit: Collider)

{

if(unhit.gameObject.name == "YourTrigger")

	{

		isCamPaused = false;

	}

}

You are using Awake in the wrong sense. Awake is called internally by the Unity Runtime Environment exactly 1 time, when the component is initialized.

You want to wrap your logic into another function and call this from your OnTriggerEnter() function like this:

function OnTriggerEnter(collision: Collider)
{
    disableCamera();
}

function disableCamera()
{
    GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false;
    GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false;
}

And btw, you are doing yourself a favour if you stop using GameObject.Find() and instead use fix references to any external objects. Also better use the generic version of GetComponent for type safety.

Cheers, Tommy

ok just to make it clear i have this script attached to a door and need the cam to stop as a gui code panel pops up to enter a key code to open the door. what im trying to say is because the code isnt attached to the First Person Controller will if be able to find the Mouse Look script

GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false;

does this part of the script search for the component everywhere or does the script only search the item it is attached to? dont know if this is very clear im just thinking because the script isnt attached to the FPC will it find a component attached to the FPC haha im a noob incase you have not already guessed so still not quite sure how everything works.

Here is a part from my game i am making it works perfect

mouseLook = gameObject.Find("Camera").GetComponent("MouseLook").enabled = true; // find the mouselook script and enable it for viweing FPS Style

I have never seen function

OnTriggerEnter(collision: Collider){


    paused();

}


   i would do this 
function OnTriggerEnter(hit : Collider)
{
    if(hit.gameObject.tag == player)
        {

GameObject.Find(“First Person Controller”).GetComponent(“Mouse Look”).enabled = false;

GameObject.Find(“Main Camera”).GetComponent(“MouseLook”).enabled = false;

        }


}