C# 使用Unity时出现NullReferenceException问题

u3d小白,搜索到的很多相似问题都无法解决,困扰了三天只能上来求助了……

Unity报错:NullReferenceException: Object reference not set to an instance of an object
Enemy_2.Start () (at Assets/_Scripts/Enemy_2.cs:21)

问题出现在21行(Start部分)

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy_2 :Enemy
{
    [Header("Set in Inspector:Enemy_2 ")]
    public float sinEccentricity = 0.6f;
    public float lifeTime = 10;

    [Header("Set Dynamically:Enemy_2 ")]
    public Vector3     p0;
    public Vector3     p1;
    public float birthTime;

    // Start is called before the first frame update 

    void Start()
    {
        p0 = Vector3.zero;
        p0.x = -bndCheck.camWidth - bndCheck.radius;
        p0.y = Random.Range(-bndCheck.camHeight, bndCheck.camHeight);

        p1 = Vector3.zero;
        p1.x = bndCheck.camWidth + bndCheck.radius;
        p1.y = Random.Range(-bndCheck.camHeight, bndCheck.camHeight);


        if (Random.value > 0.5f)
        {
            p0.x *= -1;
            p1.x *= -1;
        }
        birthTime = Time.time;

    }
    public override void Move()
    {
        float u = (Time.time - birthTime) / lifeTime;
        if (u >1)
        {
            Destroy(this.gameObject);
            return;
        }
        u = u + sinEccentricity * (Mathf.Sin(u * Mathf.PI * 2));
        pos = (1 - u) * p0 + u * p1;

    }


}

 我在这个脚本的父类中定义了变量 protected BoundsCheck bndCheck; 也已经把脚本绑定到了物体上,依然报错……执行时物体会出现在屏幕边缘,接着就会报错,被困扰了三天,求大神解答

你是说 Enemy 父类里定义了 bndCheck ?