AnimationDataHierarchal setAnimData(MovementStance state) { switch (state) { case MovementStance.IDLE: return(idleAnim); case MovementStance.WALKING: return(walkingAnim); case MovementStance.RUNNING: return(runningAnim); default: return(idleAnim); } }
// Update is called once per frame void Update() { sprint = Input.GetKey(KeyCode.LeftShift); idle = Input.GetKey(KeyCode.W); //check if different input, MovementStance updatedStance; if (!idle) { if (sprint) { updatedStance = MovementStance.RUNNING; } else { updatedStance = MovementStance.WALKING; } } else { updatedStance = MovementStance.IDLE; } if (updatedStance != currentStance) { transitionParameter = 0; lerpin = true; prevAnim = setAnimData(currentStance); currentAnim = setAnimData(updatedStance); currentStance = updatedStance; } //update framecount; //update to next frame timer += Time.deltaTime; if (timer >= currentAnim.framePerSecond) { currentFrame++; timer = 0; if (currentFrame > currentAnim.totalFrameDuration) { currentFrame = 0; } } if (lerpin) { transitionParameter += .1f; if (transitionParameter >= 1) { transitionParameter = 1; lerpin = false; } } else { transitionParameter = 1; } blendAnimation(); }
void Start() { currentStance = 0; currentAnim = idleAnim; prevAnim = idleAnim; }