Example #1
0
    void Update()
    {
        var keyboard = Keyboard.current;
        var mouse    = Mouse.current;

        if (!CanMove || keyboard == null)
        {
            return;
        }

        // Horizontal movement
        float moveHorizontal = 0.0f;

        if (keyboard.leftArrowKey.isPressed || keyboard.aKey.isPressed)
        {
            moveHorizontal = -1.0f;
        }
        else if (keyboard.rightArrowKey.isPressed || keyboard.dKey.isPressed)
        {
            moveHorizontal = 1.0f;
        }

        movementInput = new Vector2(moveHorizontal, 0);

        // Jumping input
        if (!isJumping && keyboard.spaceKey.wasPressedThisFrame)
        {
            jumpInput = true;
        }

        Vector3 screenPos    = mainCamera.ScreenToWorldPoint(mouse.position.ReadValue());
        Vector2 aimDirection = screenPos - armIK.position;

        if (!isCastingMagic)
        {
            armIK.right = isFlipped ? -aimDirection : aimDirection;
        }

        if (mouse.leftButton.wasPressedThisFrame)
        {
            wandController.ShootFireball(aimDirection.normalized);
            WandAnimation();
        }

        if (mouse.rightButton.wasPressedThisFrame)
        {
            environmentController.AddPoint(screenPos);
            if (environmentController.canUse)
            {
                WandAnimation();
            }
        }
    }