void Update()
    {
        if (!canControl)
        {
            return;
        }

        switch (playerInput.UseMobileInput)
        {
        case true:
            runState = playerInput.Run() && canRun && !isCrouching ? 1 : 0;
            inputX   = playerInput.MoveInput().x;
            inputZ   = playerInput.MoveInput().z + runState;
            crouch   = playerInput.Crouch();
            run      = playerInput.Run();
            jump     = playerInput.Jump();
            break;

        case false:
            inputX = Input.GetAxis("Horizontal");
            inputZ = Input.GetAxis("Vertical");
            crouch = Input.GetKey(crouchKey);
            run    = Input.GetKey(runKey);
            jump   = Input.GetKey(jumpKey);
            break;
        }

        if (jumpState == 0 && CanStand() && jump && jumpTimer >= antiBunnyHopFactor)
        {
            PlaySound(footSteps.jumpSound, JumpLandSource);
            jumpState++;
        }

        if ((Mathf.Abs((transform.position - contactPoint).magnitude) > 2))
        {
            landTimer = 1;
        }

        isCrouching = crouch && canCrouch;

        if (grounded)
        {
            if (isCrouching)
            {
                controller.center = Vector3.Lerp(controller.center, new Vector3(controller.center.x, -(defaultHeight - minCrouchHeight) / 2, controller.center.z), 15 * Time.deltaTime);
                controller.height = Mathf.Lerp(controller.height, minCrouchHeight, 15 * Time.deltaTime);
            }
            else
            {
                if (CanStand())
                {
                    controller.center = Vector3.Lerp(controller.center, Vector3.zero, 15 * Time.deltaTime);
                    controller.height = Mathf.Lerp(controller.height, defaultHeight, 15 * Time.deltaTime);
                }
            }
        }
    }
Beispiel #2
0
    void Update()
    {
        if (!canControl)
        {
            return;
        }

        switch (playerInput.UseMobileInput)
        {
        case true:
            runState = playerInput.Run() && canRun && !isCrouching ? 1 : 0;
            inputX   = playerInput.MoveInput().x;
            inputZ   = playerInput.MoveInput().z + runState;
            crouch   = playerInput.Crouch();
            run      = playerInput.Run();
            jump     = playerInput.Jump();
            break;

        case false:
            inputX = Input.GetAxis("Horizontal");
            inputZ = Input.GetAxis("Vertical");
            crouch = Input.GetKey(crouchKey);
            run    = Input.GetKey(runKey);
            jump   = Input.GetKey(jumpKey);
            break;
        }

        if (GameManager.Instance.GetPlayerPawn() != null)
        {
            if ((inputX != 0 | inputZ != 0) & !run)
            {
                GameManager.Instance.GetPlayerPawn().SetAnimationState(Pawn.PawnAnimatorState.Walk);
            }
            else if (run)
            {
                GameManager.Instance.GetPlayerPawn().SetAnimationState(Pawn.PawnAnimatorState.Run);
            }
            else
            {
                GameManager.Instance.GetPlayerPawn().SetAnimationState(Pawn.PawnAnimatorState.Idle);
            }
        }

        if (jumpState == 0 && CanStand() && jump && jumpTimer >= antiBunnyHopFactor)
        {
            //PlaySound(footSteps.jumpSound, JumpLandSource);

            if (SoundAndMusic.Instance != null)
            {
                SoundAndMusic.Instance.PlayPlayerJump(gameObject);
            }

            jumpState++;
        }

        if ((Mathf.Abs((transform.position - contactPoint).magnitude) > 2))
        {
            landTimer = 1;
        }

        isCrouching = crouch && canCrouch;

        if (grounded)
        {
            if (isCrouching)
            {
                controller.center = Vector3.Lerp(controller.center, new Vector3(controller.center.x, -(defaultHeight - minCrouchHeight) / 2, controller.center.z), 15 * Time.deltaTime);
                controller.height = Mathf.Lerp(controller.height, minCrouchHeight, 15 * Time.deltaTime);
            }
            else
            {
                if (CanStand())
                {
                    controller.center = Vector3.Lerp(controller.center, Vector3.zero, 15 * Time.deltaTime);
                    controller.height = Mathf.Lerp(controller.height, defaultHeight, 15 * Time.deltaTime);
                }
            }
        }
    }