【问题标题】:Unity animations - yield return new WaitForSeconds(secs) not workingUnity 动画 - 产量返回新的 WaitForSeconds(secs) 不起作用
【发布时间】: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());

标签: c# animation unity3d wait


【解决方案1】:

这就是你运行协程的方式:

StartCoroutine(Attack());

StartCoroutine("Attack");

如果您尝试像通常的功能一样运行它,它将无法工作。

所以这里是解决方案:

public void PlayAttack() 
{
    StartCoroutine(Attack());
}

Learn More

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 2015-06-14
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多