从协程播放的 Unity 动画
Unity Animation playing from coroutine
正如标题所说,动画没有播放。告诉它播放的行在协程中,代码在 waitforseconds(3f) 之前。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Play : MonoBehaviour {
public Animator AnimatorRef;
// Use this for initialization
void Start () {
if (AnimatorRef == null)
{
AnimatorRef = GetComponent<Animator>();
}
}
public void PlayGame()
{
StartCoroutine(TitlePlay());
Debug.Log("playing");
}
IEnumerator TitlePlay()
{
Debug.Log("playing1");
AnimatorRef.SetBool("Enlarge", true);
yield return new WaitForSeconds(3f);
Debug.Log("playing2");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
它很好地抓住了动画师参考,并且所有三个评论都显示了。
2 个注意事项。
- 第 1 -
你检查过你的转换和 AnimationController 了吗?
您可以打开 AnimationController 查看 bool 在 运行 时间内是否发生变化,如果发生变化,您就会知道动画状态之间存在转换错误。
- 第二 -
如果注释掉 "LoadScene" 部分,动画能正常播放吗?
我怀疑在整个方法 运行 通过之前,动画布尔出于某种原因不允许执行它的操作,但可能是错误的。
我的 unity 没有保存就关闭了,但它现在可以工作了。如果有人遇到此问题,请重新制作动画并确保您从初始动画开始并单击添加剪辑。然后它对我有用:)
正如标题所说,动画没有播放。告诉它播放的行在协程中,代码在 waitforseconds(3f) 之前。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Play : MonoBehaviour {
public Animator AnimatorRef;
// Use this for initialization
void Start () {
if (AnimatorRef == null)
{
AnimatorRef = GetComponent<Animator>();
}
}
public void PlayGame()
{
StartCoroutine(TitlePlay());
Debug.Log("playing");
}
IEnumerator TitlePlay()
{
Debug.Log("playing1");
AnimatorRef.SetBool("Enlarge", true);
yield return new WaitForSeconds(3f);
Debug.Log("playing2");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
它很好地抓住了动画师参考,并且所有三个评论都显示了。
2 个注意事项。
- 第 1 -
你检查过你的转换和 AnimationController 了吗?
您可以打开 AnimationController 查看 bool 在 运行 时间内是否发生变化,如果发生变化,您就会知道动画状态之间存在转换错误。
- 第二 -
如果注释掉 "LoadScene" 部分,动画能正常播放吗?
我怀疑在整个方法 运行 通过之前,动画布尔出于某种原因不允许执行它的操作,但可能是错误的。
我的 unity 没有保存就关闭了,但它现在可以工作了。如果有人遇到此问题,请重新制作动画并确保您从初始动画开始并单击添加剪辑。然后它对我有用:)