0
我有一个剧本叫“trigger.cs”实例化的预制。该脚本附加到预制件中的对象。预制件在运行时实例化。统一分配游戏物体,其在运行时
此外,如果我能以某种方式硬编码“死亡菜单”,这也将是一个解决办法。
这里是我的trigger.cs文件
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class trigger : MonoBehaviour {
public Text scoreText;
public Death deathMenu;
//the line below is commented because its not working for me and just throws an error.
//public Death deathMenu = GameObject.Find("Death Menu");
void Start(){
}
// Update is called once per frame
void Update() {
}
void OnTriggerEnter (Collider othercollider){
Debug.Log ("You Are Dead !");
}
}
好吧...我已经试过这两个....没有,NT显示我的任何错误......但是当我运行游戏,它说“的NullReferenceException:对象引用未设置为实例一个对象“ – Simon
现在我们来关注第一个。 'deathMenu = GameObject.Find(“Death Menu”);'正在导致'NullReferenceException'?你有没有把它放在'开始'功能?如果是的话,你可以把它放在唤醒功能吗? – Programmer
第一个工作正常...没有错误没有任何....但由于某种原因,它仍然是空的...和空我的意思是这样的:https://i.stack.imgur.com/99cfl .png – Simon