Hello:), so this script is meant to deactivate a SafeLock Script at first, and then when the player hits “E”, the SafeLock Script gets activated (Shows a keyboard(GUI) where you write the right combination to unlock a safe). The proble is that the activation and deactivation of the SafeLock Script is working (when I press “E” near the safe it shows the GUI). But all the other variables that i wanted affected(walking, moving the camera, run, turn my flashlight on/off), are not being affected… Unity displays an error that says:
“NullReferenceException: Object reference not set to an instance of an object
SafeLockOnE.Update () (at Assets/SafeLockOnE.js:37)”
So when the player aproaches the safe and press “E”, the Gui gets displayed, but i can still walk, move the camera, run, turn my flashlight on/off, etc…What should I do?? Please Help
This is the Scipt:
var range: float = 5;
private var hit: RaycastHit;
var SafeLockMeca : SafeLock;
var lookAround01 : MouseLook;
var lookAround02 : MouseLook;
var charMotor : CharacterMotor;
var charMotor2 : FPSWalkerEnhaced;
var FlashlightHide : FlashLight;
var HideCursor : HideMouseCursor;
function Start ()
{
SafeLockMeca = gameObject.GetComponent(SafeLock);
lookAround01 = gameObject.GetComponent(MouseLook);
lookAround02 = GameObject.Find("MainCamera").GetComponent(MouseLook);
charMotor = gameObject.GetComponent(CharacterMotor);
charMotor2 = gameObject.GetComponent(FPSWalkerEnhaced);
FlashlightHide = GameObject.Find("FlashLight").GetComponent(FlashLight);
HideCursor = GameObject.Find("Player").GetComponent(HideMouseCursor);
SafeLockMeca.enabled = false;
}
function Update(){
if (Input.GetKeyDown("e")){
var ray = Camera.main.ViewportPointToRay(Vector3(0.5,0.5,0));
if (Physics.Raycast(ray, hit, range)){
SafeLockMeca.enabled = true;
lookAround01.enabled = false;
lookAround02.enabled = false;
charMotor.enabled = false;
charMotor2.enabled = false;
FlashlightHide.enabled = false;
HideCursor.enabled = false;
}
}
}