Пример #1
0
    private void PerformMovement(DirectionalBehavior behavior)
    {
        Vector3 moveVector = behavior.MoveDirection * WalkSpeed;

        moveVector.y = Physics.gravity.y;
        moveVector  *= Time.deltaTime;

        _controller.Move(moveVector);
    }
Пример #2
0
    public void Update()
    {
        if (_isPaused)
        {
            return;
        }

        DirectionalBehavior behavior = CheckInput();

        PerformMovement(behavior);
        Animate(behavior);
    }
Пример #3
0
    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);
    }
Пример #4
0
 private void Animate(DirectionalBehavior behavior)
 {
     _sprite.PlaySingleFrame(behavior.ActionAnimation, false, AnimationMode.Loop);
 }
Пример #5
0
    private void PerformMovement(DirectionalBehavior behavior)
    {
        Vector3 moveVector = behavior.MoveDirection * WalkSpeed;
        moveVector.y = Physics.gravity.y;
        moveVector *= Time.deltaTime;

        _controller.Move(moveVector);
    }
Пример #6
0
 private void Animate(DirectionalBehavior behavior)
 {
     _sprite.PlaySingleFrame(behavior.ActionAnimation, false, AnimationMode.Loop);
 }