this._animator = transform.GetComponent<Animator>();
int stateid = Animator.StringToHash("wait");
bool hasAction = this._animator.HasState(0, stateid);
if (hasAction)
{
//单一动作重复调用时需要使用Play方法而且需把所有参数填写完整
this._animator.Play("wait", 0, 0);
}
Unity 使用HasState判断Animator中是否存在动画
最新推荐文章于 2025-02-13 19:05:40 发布
这篇博客介绍了如何在 Unity 游戏引擎中使用 Animator 组件来控制角色的状态。通过 `GetComponent<Animator>()` 获取 Animator 实例,然后利用 `Animator.StringToHash(wait)` 转换字符串为哈希值,检查是否存在 'wait' 状态。如果存在,使用 `Play()` 方法播放等待状态。这展示了在游戏开发中如何实现角色行为的切换。
6509





