在泰斗社区看到了关于unity状态机判断动画完成的帖子,觉得可能有人也会需要,现在就把它分享到这。
1. 脚本参考
AnimatorStateInfo.normalizedTimefloat normalizedTime;
Description:
Normalized time of the State.
The integer part is the number of time a state has been looped. The fractional part is the % (0-1) of progress in the current loop.
2. 代码如下:private Animator animator;
void Start()
{
animator = this.GetComponent<Animator>();
}
void Update()
{
AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
// 判断动画是否播放完成
if( info.normalizedTime >= 1.0f)
{
DoSomething();
}
}