2016-11-11 60 views
0

爲什麼Unity中的動畫不能在Unity中播放?我該如何讓程序等待動畫結束?在JavaScript(或UnityScript)中,這種方法已經奏效。統一動畫 - 收益率返回新的WaitForSeconds(秒)不起作用

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; 
} 
+0

你在哪裏運行協同程序? –

+0

您需要調用/啓動'Attack()'協程函數。 'StartCoroutine(攻擊());' – Programmer

回答

0

這是你如何運行協程:

StartCoroutine(Attack()); 

StartCoroutine("Attack"); 

如果試圖像通常的功能,它不會工作運行它。

所以這裏是解決方案:

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

Learn More