【发布时间】:2016-11-11 17:04:40
【问题描述】:
当我使用此代码时,为什么动画在 Unity 中不播放?我怎样才能让程序等待动画结束?在 JavaScript(或 UnityScript)中,这种方法很有效。
public bool Attacking { get; set; }
private Animator anim;
void Start()
{
anim = gameObject.GetComponent<Animator>();
}
private IEnumerator Attack()
{
Attacking = true;
anim.SetTrigger("Attack"); // this is not playing
yield return new WaitForSeconds(attackLength);
Attacking = false;
}
【问题讨论】:
-
你在哪里运行协程?
-
你需要调用/启动
Attack()协程函数。StartCoroutine(Attack());