isPlaying报错了
时间: 2023-07-19 18:24:36 浏览: 50
如果 `isPlaying` 函数报错了,可能是因为该函数已经在 Unity 5.3 版本后被废弃。推荐使用 `GetCurrentAnimatorStateInfo` 函数或者 `GetCurrentAnimatorClipInfo` 函数来判断当前动画是否播放完毕。
使用 `GetCurrentAnimatorStateInfo` 函数的示例代码如下:
```
void Update()
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.normalizedTime >= 1.0f && stateInfo.IsName("AnimationName"))
{
// 启用控制器
playerController.enabled = true;
}
}
```
其中,`animator.GetCurrentAnimatorStateInfo(0)` 获取当前动画状态信息,`stateInfo.normalizedTime` 表示动画播放的时间长度占整个动画长度的比例,当 `normalizedTime` 值大于等于 1.0f 时,表示动画播放完毕。`stateInfo.IsName("AnimationName")` 判断当前动画状态是否为指定的动画名称。
如果使用 `GetCurrentAnimatorClipInfo` 函数,则代码如下:
```
void Update()
{
AnimatorClipInfo[] clipInfo = animator.GetCurrentAnimatorClipInfo(0);
if (clipInfo.Length > 0 && clipInfo[0].clip.name == "AnimationName" && clipInfo[0].clip.length <= clipInfo[0].weight)
{
// 启用控制器
playerController.enabled = true;
}
}
```
其中,`animator.GetCurrentAnimatorClipInfo(0)` 获取当前动画片段信息,`clipInfo[0].clip.name` 表示当前动画片段的名称,`clipInfo[0].clip.length` 表示当前动画片段的长度,`clipInfo[0].weight` 表示当前动画片段的权重。当当前动画片段名称为指定的名称,并且动画片段的长度小于等于动画片段的权重时,表示动画播放完毕。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)