2017-08-14 35 views
0

我可以翻轉游戲對象,但我的問題是它在攻擊動畫開始之前翻轉。我不知道如何整理這個。希望有人能幫助。unity 5:按特定順序翻轉一個遊戲對象

// Update is called once per frame 
void Update() { 

    if(Input.GetKeyDown(KeyCode.Space)) 
    { 
     GetComponent<Rigidbody2D>().velocity = new Vector2(4f, 0);  
     StartCoroutine(enemyReturn()); 
    } 
} 

IEnumerator enemyReturn() 
{ 
    yield return new WaitForSeconds(1.1f); 
    GetComponent<Animator>().SetTrigger("slimeMelee"); //attack animation 
    GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0); 
    Vector3 theScale = transform.localScale; theScale.x *= -1; 
    transform.localScale = theScale; 
} 

回答

0

一個平凡解將是fliping之前以得到一段時間:

IEnumerator enemyReturn() 
{ 
    yield return new WaitForSeconds(1.1f); 
    GetComponent<Animator>().SetTrigger("slimeMelee"); //attack animation 
    yield return new WaitForSeconds(0.5f); // Setup this yield time. 
    GetComponent<Rigidbody2D>().velocity = new Vector2(0, 0); 
    Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; // code to flip 
} 

在這個例子中,代碼會產生0.5秒之前進行翻轉。你應該改變它適合動畫的時間0.5

+0

感謝您的幫助 –