c# - unity 5: Flip a gameobject in a certain order -
i able flip gameobject problem flips before attack animation starts. don't know how put in order. hoping can help.
// update 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; }
one trivial solution yield time before fliping:
ienumerator enemyreturn() { yield return new waitforseconds(1.1f); getcomponent<animator>().settrigger("slimemelee"); //attack animation yield return new waitforseconds(0.5f); // setup yield time. getcomponent<rigidbody2d>().velocity = new vector2(0, 0); vector3 thescale = transform.localscale; thescale.x *= -1; transform.localscale = thescale; // code flip }
in example, code yield 0.5 seconds before make flip. should change 0.5
time fits animation.
Comments
Post a Comment