private void PerformMovement(DirectionalBehavior behavior) { Vector3 moveVector = behavior.MoveDirection * WalkSpeed; moveVector.y = Physics.gravity.y; moveVector *= Time.deltaTime; _controller.Move(moveVector); }
public void Update() { if (_isPaused) { return; } DirectionalBehavior behavior = CheckInput(); PerformMovement(behavior); Animate(behavior); }
private DirectionalBehavior CheckInput() { Vector2 inputVector = ReadAxes(); bool idle = inputVector == Vector2.zero; string actionModifier = idle ? IdlePart : MovePart; string directionModifier = ReadDirectionFromInputVector(inputVector); _lastDirection = directionModifier; DirectionalBehavior result = Behaviors.FirstOrDefault(b => b.HasState(actionModifier, directionModifier)); if (result == default(DirectionalBehavior)) { if (DebugMode) { Debug.Log(string.Format("No Behavior exists for a {0} state facing {1}.", actionModifier, directionModifier)); } } return(result); }
private void Animate(DirectionalBehavior behavior) { _sprite.PlaySingleFrame(behavior.ActionAnimation, false, AnimationMode.Loop); }