如何在销毁GameObject之前播放动画?

时间:2017-11-02 06:59:40

标签: c# unity3d

我遵循了这个tip,但是我根据我的C#脚本进行了调整。我的死亡动画不会在死亡中播放。那是为什么?

我已将动画附加到剧本(当敌人的生命值为0时播放)。 enter image description here

这是我的代码

public class EnemyHealthManager : MonoBehaviour {

    ... 

    private Animator fireAnimator;
    public AnimationClip fireDeathAnimation;

    // Use this for initialization
    void Start() {
        currentHealth = maxHealth;
        fireAnimator = GetComponent<Animator> ();
    }

    // Update is called once per frame
    void Update() {
        if (currentHealth <= 0)
        {

            fireAnimator.Play(fireDeathAnimation.name); //play Fire_Death animation on death
            Destroy(gameObject, 1.0f);  //dies after 1.0f seconds so that death animation can play
        }
    }

}

0 个答案:

没有答案