unity 动画结束 后处理事件

1.GetCurrentAnimatorStateInfo方法判断动画播放

public class Test : MonoBehaviour
{
    private Animator animator;
    private AnimatorStateInfo info;
 
    void Awake()
    {
        animator = GetComponent();
    }
 
    void Update()
    {
        info = animator.GetCurrentAnimatorStateInfo(0);
        if (info.normalizedTime >= 1) // 判断动画播放结束normalizedTime的值为0~1,0为开始,1为结束。
        {
            gameObject.SetActive(false);
        }
    }
}

2.在动画结束帧后面加个动画事件

3.获取动画时长

/// 
/// 获得animator下某个动画片段的时长方法
/// 
/// Animator组件 
/// 要获得的动画片段名字
/// 
public float GetAnimatorLength(Animator animator ,string name)
{
	//动画片段时间长度
    float length = 0;
    AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
    Debug.Log(clips.Length);
    foreach (AnimationClip clip in clips)
    {
        Debug.Log(clip.name);
        if (clip.name.Equals(name))
        {
            length = clip.length;
            break;
        }
    }
    return length;
}

你可能感兴趣的:(Unity,Animator,unity,Animator)