团结5:按特定顺序翻转游戏对象

时间:2017-08-14 15:49:44

标签: c# unity5 unity2d

我能够翻转游戏对象但我的问题是它在攻击动画开始之前翻转。我不知道如何按顺序排列。希望有人可以提供帮助。

// 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;
}

1 个答案:

答案 0 :(得分:0)

一个微不足道的解决方案是在腾飞前留出一些时间:

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

相关问题