Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by fernandovt · Oct 23, 2013 at 12:15 AM · menurespawnnullreference

Trying to refer to my Scripts, not working...?

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)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fernandovt · Oct 23, 2013 at 12:17 AM 0
Share

Sorry, the Bold lines didn't show as I expected -->(**)

avatar image meat5000 ♦ · Oct 23, 2013 at 12:26 AM 0
Share

Add comments ins$$anonymous$$d :)

 //Error here etc
avatar image fernandovt · Oct 23, 2013 at 01:12 AM 0
Share

Thanks;), any idea how i can solve my problem?:)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SilentSin · Oct 23, 2013 at 12:41 AM

The obvious answer is that the game object doesn't actually have those scripts on it (or one is missing).

call Debug.Log(HideCursor); and the same for FlashlightHide immediately after you assign them to see if they're null or not.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fernandovt · Oct 23, 2013 at 01:05 AM 0
Share

I think you are right, but the "Hide$$anonymous$$ouseCursor" Script is attached to the "Player" itself and the "FlashLight" Script to a normal Spotlight wich is attached to the "$$anonymous$$ainCamera"... As i'm a bit new on this I don't know how I can refer to this objects in particular in the script, how should i do it??, Can you help me?

avatar image
0

Answer by fernandovt · Oct 23, 2013 at 01:46 AM

Ok I found the solution to the flashlight here is what i did:)

1) var FlashlightHide : FlashLight; 2) FlashlightHide = GameObject.Find("FlashLight").GetComponent(FlashLight); 3) FlashlightHide.enabled =false;

The HideCursor thing didn't work, but i'm happy with the flashlight at least:)

The HideMouseCursor Script is attached to the player, i tried this and it still doesn't work:

1) var HideCursor : HideMouseCursor;

2) HideCursor = GameObject.Find("Player").GetComponent(HideMouseCursor);

3) HideCursor.enabled =false;

PD: The cursor Script:

function Update () { Screen.showCursor = false; }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How could I have a ball chooser menu? 1 Answer

Finding the player that walked into a ray? 1 Answer

A do nothing script? 2 Answers

add lockcursor to pause menu script?? 2 Answers

Respawn Problem 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges