【发布时间】:2018-01-30 20:09:10
【问题描述】:
我在我的 FPS 游戏中使用 UFPS。 UFPS 有一个类 vp_DamageHandler。它附着在我的目标上。在这个类里面,有:
public virtual void Die()
{
dieFunctionCalled = true; //the only thing I've added to this class, besides declaring dieFunctionCalled
...some UFPS code...//among other things, this is where the object is destroyed or deactivated
}
我想让原始文件尽可能干净。我想用不同的脚本编写自己的代码以保持整洁。
我想在目标死亡时做一些其他事情,所以我也将myScript 添加到我的目标中,并尝试了这个:
void Update () {
if (GetComponent<vp_DamageHandler> ().dieFunctionCalled) {
GetComponent<vp_DamageHandler> ().dieFunctionCalled = false;
Debug.Log ("dieFunctionCalled");
}
}
问题是目标在 dieFunctionCalled 设置为 true 之前就被销毁了。因此,一旦目标死亡,myScript 就会被停用并且不会记录dieFunctionCalled。如果我要重生目标,dieFunctionCalled 会出现在控制台中。
我尝试将myScript 附加到一个空的游戏对象,但后来我得到了
对象引用未设置为对象的实例
谁能帮我解决这个问题?我是 Unity 的新手。基本上,我想要的只是保持原始 UFPS 文件尽可能干净,并将所有脚本写入不同的文件中。
【问题讨论】: