Unity C# - 未将对象引用设置为对象的实例

时间:2016-07-19 21:29:35

标签: c# unity3d null

我试图让我的另一个脚本的实例调用其中一个方法,但无论我尝试什么,我都会收到此错误:

NullReferenceException: Object reference not set to an instance of an object
ZombieBulletHitManager.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/ZombieBulletHitManager.cs:22)

这是 ZombieBulletManager 的代码:

using UnityEngine;
using System.Collections;

public class ZombieBulletHitManager : MonoBehaviour {

// Use this for initialization  
void Start () {

}

// Update is called once per frame
void Update () {

}

void OnTriggerEnter2D(Collider2D other) {
    if(other.gameObject.ToString().StartsWith("ZombieBullet")){
    // Add the blood animation.
    spawnBlood();

    // Destroying the game objects
    gameObject.GetComponent<ArcherBulletShootHandler>().removeBullet(other.gameObject);
    Destroy (other);
    Destroy(gameObject);
    }
}   

private void spawnBlood(){
    GameObject go = Instantiate(
        Resources.Load<GameObject>("ZombieBlood"),
        transform.position,
        Quaternion.identity) as GameObject;
     }
}

编辑:显然这是一个副本,但它没有,我不知道 gameObject.GetComponent()行中的null是什么.removeBullet(other.gameObject) ;

任何帮助都会很棒,谢谢!

0 个答案:

没有答案