//获取到Animator组件
_animator = gObj.GetComponentInChildren<Animator>();
var animatorStateNames = new List<string>(); if (_animator != null) { if (_animator.runtimeAnimatorController is AnimatorController aniController) { var stateMachine = aniController.layers[0].stateMachine; foreach (var it in stateMachine.states) { animatorStateNames.Add(it.state.name); } } }
其实这里是想在播放前判断状态是否存在,网上找到另外方法:Unity 使用HasState判断Animator中是否存在动画_unity hasstate-CSDN博客