void UpdateAnimation() { string newDirection; HanleInput(out newDirection); // continue using the last direction when the character stops moving if (newDirection == DirectionType.None) { newDirection = _lastDirection; } bool sameAction = _lastDirection == newDirection && _lastInput == _newInput; _charAnimator.UpdateAnimationTime(1 / SpeedAnimation); if (!sameAction || Player.CharacterDNA.IsDirty()) { AnimationManager.UpdateDNAForAction(Player.CharacterDNA, Player.AnimationDNA, _newAction, newDirection); _charAnimator.AnimateAction(Player.AnimationDNA, _newAction); } else if (!Input.anyKey && !_isStillMoving) { _charAnimator.ResetAnimation(); } _lastDirection = _newAction.Direction = newDirection; _lastInput = _newInput; }
private void UpdateAnimation() { var newDirection = DirectionType.None; if (Input.GetKeyDown(KeyCode.W) && _newInput != KeyCode.W) { newDirection = DirectionType.Up; _newAction = new WalkAction(); _newInput = KeyCode.W; } else if (Input.GetKeyDown(KeyCode.A) && _newInput != KeyCode.A) { newDirection = DirectionType.Left; _newAction = new WalkAction(); _newInput = KeyCode.A; } else if (Input.GetKeyDown(KeyCode.S) && _newInput != KeyCode.S) { newDirection = DirectionType.Down; _newAction = new WalkAction(); _newInput = KeyCode.S; } else if (Input.GetKeyDown(KeyCode.D) && _newInput != KeyCode.D) { newDirection = DirectionType.Right; _newAction = new WalkAction(); _newInput = KeyCode.D; } else if (Input.GetKeyDown(KeyCode.Space)) { _newAction = new SlashAction(); _newInput = KeyCode.Space; SpeedAnimation = 1.0f; } else if (Input.GetKeyDown(KeyCode.F)) { _newAction = new ThrustAction(); _newInput = KeyCode.F; SpeedAnimation = 1.0f; } else if (Input.GetKeyDown(KeyCode.R)) { _newAction = new SpellcastAction(); _newInput = KeyCode.R; SpeedAnimation = 1.0f; } else if (Input.GetKeyDown(KeyCode.E)) { _newAction = new ShootAction(); _newInput = KeyCode.E; SpeedAnimation = 1.0f; } else if (Input.GetKeyDown(KeyCode.X)) { _newAction = new DeathAction(); _newInput = KeyCode.X; SpeedAnimation = 1.0f; } else { _newInput = KeyCode.None; } // continue using the last direction when the character stops moving if (newDirection == DirectionType.None) { newDirection = _lastDirection; } var sameAction = _lastDirection == newDirection && _lastInput == _newInput; _charAnimator.UpdateAnimationTime(1 / SpeedAnimation); if (!sameAction || Player.CharacterDNA.IsDirty()) { AnimationManager.UpdateDNAForAction(Player.CharacterDNA, Player.AnimationDNA, _newAction, newDirection); _charAnimator.AnimateAction(Player.AnimationDNA, _newAction); } else if (!Input.anyKey && !_isStillMoving) { _charAnimator.ResetAnimation(); } _lastDirection = _newAction.Direction = newDirection; _lastInput = _newInput; }