Hey, I have a working script that dissables MouseLook, CharacterMovement etc. And displays in the screen Menu, and Respawn. The thing is that i did not write it entirely and I was playing around thinking that i can improve it and disable more actions from the player (because in the respawn menu i can still turn a flashlight on and of (flashlight is a simple light in the MainCamera), and my HideMouseCursor it’s still hided, when it should be visible to click “Menu” or “Respawn”.
Well the problem is that i tried to disable this scripts in the same way the other scripts where disabled, and it doesn’t work in that way…, the Console shows this error :
NullReferenceException: Object reference not set to an instance of an object
RespawnMenu.Update () (at Assets/Scripts Mios/RespawnMenu.js:30)
This is the Script, the Bold lines are the lines that i writed, and are not working…(PD: Sorry for my English haha):
var lookAround01 : MouseLook;
var lookAround02 : MouseLook;
var charMotor : CharacterMotor;
var charMotor2 : FPSWalkerEnhaced;
**var HideCursor : HideMouseCursor;
var FlashlightHide : FlashLight;**
static var playerIsDead = false;
function Start ()
{
lookAround01 = gameObject.GetComponent(MouseLook);
lookAround02 = GameObject.Find("MainCamera").GetComponent(MouseLook);
charMotor = gameObject.GetComponent(CharacterMotor);
charMotor2 = gameObject.GetComponent(FPSWalkerEnhaced);
**HideCursor = gameObject.GetComponent(HideMouseCursor);
FlashlightHide = gameObject.GetComponent(FlashLight);**
}
function Update ()
{
if (playerIsDead == true)
{
lookAround01.enabled = false;
lookAround02.enabled = false;
charMotor.enabled = false;
charMotor2.enabled =false;
**HideCursor.enabled =false;
FlashlightHide.enabled =false;**
}
}
function OnGUI ()
{
if (playerIsDead == true)
{
if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40), "Respawn"))
{
RespawnPlayer();
}
if (GUI.Button(Rect(Screen.width*0.5-50, 240, 100, 40), "Menu"))
{
Debug.Log("Return to Menu");
}
}
}
function RespawnPlayer ()
{
Debug.Log("Respawn Player");
}
@script RequireComponent(CharacterController)