【发布时间】:2015-09-19 16:50:49
【问题描述】:
我创建了一个带有精灵表动画的预制件,我想在玩家死亡时播放它。我通过在场景中拖动预制件来检查它是否正在工作,并且它可以无休止地循环播放精灵表的每一帧。
现在我想在玩家死亡时播放这个预制件,并在它结束后销毁它,但到目前为止我只能将它放置在玩家死亡的地方,并且它会永远留在那里。发生这种情况时也会出现一些错误。
这是死亡脚本:
public class DmgByCollisionEnemy : MonoBehaviour {
public GameObject deathAnimation;
void Die() {
deathAnimation = (GameObject) Instantiate(deathAnimation, transform.position, transform.rotation);
//Destroy(deathAnimation);
Destroy(gameObject);
}
}
我通过在Unity界面中拖动一个预制件来设置deathAnimation。
Die() 方法触发时出现的错误是
UnassignedReferenceException: The variable deathAnimation of DmgByCollisionEnemy has not been assigned.
You probably need to assign the deathAnimation variable of the DmgByCollisionEnemy script in the inspector.
那么我该如何正确地做到这一点呢?
【问题讨论】:
标签: c# unity3d unity3d-2dtools