如何判断Animator动画是否播放完成

2024-12-28 17:52:05
推荐回答(1个)
回答1:

1. 脚本参考
AnimatorStateInfo.normalizedTime
float 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();
}

void Update()
{
AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
// 判断动画是否播放完成
if( info.normalizedTime >= 1.0f)
{
DoSomething();
}
}