当我使用这段代码时,为什么动画不能在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;
}发布于 2016-11-11 17:10:35
这就是你如何运行Coroutine的方法:
StartCoroutine(Attack());或
StartCoroutine("Attack");如果你试着像普通的函数一样运行它,它就不能工作了。
以下是解决方案:
public void PlayAttack()
{
StartCoroutine(Attack());
}https://stackoverflow.com/questions/40552858
复制相似问题