您当前的位置: 首页 >  unity

云小川

暂无认证

  • 9浏览

    0关注

    78博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity 动画结束 后处理事件

云小川 发布时间:2022-08-05 15:01:55 ,浏览量:9

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;
}

关注
打赏
1663746399
查看更多评论
立即登录/注册

微信扫码登录

0.4526s