Hanyuuuu 2021-03-30 21:36 采纳率: 50%
浏览 196
已采纳

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行

 

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;

    }


}
 

  • 写回答

1条回答 默认 最新

  • 幻灰龙 2021-03-30 21:44
    关注

    bndCheck 变量没有定义和赋值就使用

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行