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)
Looks like you need to find and reference the objects that those scripts are on.
Just like this line (eg) lookAround02 = GameObject.Find(“MainCamera”).GetComponent(MouseLook);.
Example code
var yourVar : MonoBehaviour;
if(GameObject.Find(objectName)) {
yourVar = GameObject.Find("objectName").GetComponent(ScriptName);
}
if(yourVar) {
yourVar.enabled = false;
}
I tried but I don’t know exactly what you mean, I think I’m doing something wrong in the “objectName” part of your script, I tried this but the same problem gets displayed…
var lookAround01 : MouseLook;
var lookAround02 : MouseLook;
var charMotor : CharacterMotor;
var charMotor2 : FPSWalkerEnhaced;
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);
FlashlightHide = GameObject.Find(“MainCamera”).GetComponent(FlashLight); //Something is wrong here…
}
function Update ()
{
if (playerIsDead == true)
{
lookAround01.enabled = false;
lookAround02.enabled = false;
charMotor.enabled = false;
charMotor2.enabled =false;
FlashlightHide.enabled =false; //Don’t work…
FlashLi ght prob needs to be FlashLight.
“MainCamera” is correct. GameObject names need the " " Double quotes. Think I forgot them in my example - lol
(Tip) - If you use the Go Advanced Button you can place your code in tags so it looks nice and neat.
Also check (MouseLo ok) - 
I solved the problem:), The Flashlight now stops working as i wanted, and the cursor almost did, but i find that i was not refering to the right places, i guess the hidecursor thing will not work, but i’m happy that at least it worked oin the flashlight:), this is what i did
1)
var FlashlightHide : FlashLight;
var HideCursor : HideMouseCursor;
FlashlightHide = GameObject.Find(“FlashLight”).GetComponent(FlashLight);
HideCursor = GameObject.Find(“Player”).GetComponent(HideMouseCursor);
FlashlightHide.enabled =false;
HideCursor.enabled =false;
Thanks a lot for your help and patience Black Mantis:)
Here is the HideMouseCursor Script, i post it just if you know what to do to make it appear when this RespawnMenu script gets activated. (The HideMouseCursor Script it’s attached to the player, and it gets activated as soon the game plays, it’s a really simple script):
function Update () {
Screen.showCursor = false;
}
Please edit your posts and mark your code with the code tag. You will find people are a lot more willing to help when your code is readable.
You will need to use the ‘Go Advanced’ option when replying or editing to do so.