Вопрос

I am seeing the Walker boys tutorial, Im on the Project #2, where you make a ship that destroys asteroids... and there's a part where the bullet must call a function from other object... (here's the video http://vimeo.com/19463502) I do everything that is here but I get this error:

"NullReferenceException: Object reference not set to an instance of an object
scriptBullet.OnTriggerEnter (UnityEngine.Collider other) (at Assets/scriptBullet.js:39)

and that line of code is :

sceneManager.transform.GetComponent(scriptsceneManager).AddScore();

scriptsceneManager.js

   var gameTime : float = 60;
     static var score : int = 0;
    function Update () 
    {
    print("score : " +score);

    }

    public function AddScore()
    {
     score +=1;
    }
Это было полезно?

Решение

From what i can see (it's been a while since i did the walkerboy tutorials) there are only 2 reason why you can get a NullPointerException here.

  1. The SceneManager has not been initialised in scriptBullet.js. If you are finding the GameObject by Tag make sure you have the tag assigned and is spelled correctly in the script. I always forget to assign tags until it's no late.

  2. The scriptsceneManager hasn't been added to the SceneManager object. This results in the GetComponent call returning null.

If you are using Monodevelop, remember if you hit the attach button, you can attach UnityEditor to monodevelop, then you can use breakpoints to find out where the NullPointer is coming from. https://docs.unity3d.com/Documentation/Manual/Debugger.html

Hope this helps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top