Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why NullReferenceException??

Discussion in 'Scripting' started by fernandovt, Apr 5, 2014.

  1. fernandovt

    fernandovt

    Joined:
    Oct 1, 2012
    Posts:
    67
    Unity tells me that i have a problem in my script but i don't get what i need to change on it to make it work, this is the problem:

    NullReferenceException: Object reference not set to an instance of an object
    PickUpCamera.Start () (at Assets/PickUpCamera.js:14)

    This is the Script:

    Code (csharp):
    1.  
    2. var DigitalCameraHide : DigitalCameraScript;
    3. //
    4. var DigitalCameraObject: GameObject;
    5. var PickupSound: AudioClip;
    6.  
    7. private var inTrigger = false;
    8. //
    9. private var hasDigitalCameraScript = false;
    10. function Start ()  
    11. {
    12.  
    13. DigitalCameraHide = GameObject.Find("Player").GetComponent(DigitalCameraScript);  
    14. DigitalCameraHide.enabled = false;      
    15.  
    16.  
    17.  
    18. }
    19.  
     
  2. Cynikal

    Cynikal

    Joined:
    Oct 29, 2012
    Posts:
    122
    Are you sure you have a game object named "Player" that has the DigitalCameraScript on it?

    Because it's not finding it.