c# - How to manage animations? -
c# - How to manage animations? -
i'm using c# , i'm building 3rd person view game. have 3d character model animations in frames have cutting animations frame
the problem have 5 animations (idle, run, walk, punch, jump) , code
void update () { if (input.getaxis("horizontal") != 0 || input.getaxis("vertical") != 0){ //play run animation } else { if (motion.x != 0 || motion.z != 0){ motion.x = 0; motion.z = 0; } //play idle anim } if (input.getkeydown(keycode.space) && controller.isgrounded){ //play jump anim } if (input.getkeydown(keycode.p)){ //play punch anim } if (!controller.isgrounded){ //play jump anim } vertvelo -= gravity * time.deltatime; motion.y = vertvelo; this.controller.move(motion * time.deltatime); }
the problem occurs when press p create character punch. seems idle animation in update function beingness called punch animation doesn't have time play.
so, what's solution? there animation managing technique or should utilize delay?
you may block idle animation while punch playing (but may it's not best approach):
bool ispunchplaying = false; void update () { //... if (!ispunchplaying) { // play idle anim } // ... if (input.getkeydown(keycode.p)){ //play punch anim ispunchplaying = true; startcoroutine(waitthendopunch(animation["punch"].length)); } // ... } ienumerator waitthendopunch(float time) { yield homecoming new waitforseconds(time); ispunchplaying = false; }
c# animation unity3d
Comments
Post a Comment