如何获取unity中animationController中的animationstate
您可以使用以下代码获取AnimationController中的AnimationState:
// 获取动画控制器
Animator animator = GetComponent<Animator>();
// 获取所有动画状态
AnimatorStateInfo[] animationStates = animator.GetCurrentAnimatorStateInfo(0).GetAllAnimationStates();
foreach (AnimatorStateInfo animationState in animationStates)
{
// 获取动画状态的名称
string animationName = animationState.shortNameHash.ToString();
// 获取动画状态的时间信息
float animationTime = animationState.normalizedTime;
}
这里使用了Animator.GetCurrentAnimatorStateInfo(0).GetAllAnimationStates()方法来获取所有动画状态。然后,可以遍历动画状态并获取它们的名称和时间信息。
原文地址: https://www.cveoy.top/t/topic/b2uO 著作权归作者所有。请勿转载和采集!