void Jump()
    {
        if (m_NumberOfJumps > 0)
        {
            m_PlayerAnimator.SetInteger("AnimationState", 1);
            if (!m_IsSliding)
            {
                m_AnimationState = AnimationState.JUMPING;

                m_IsJumping = true;
                m_NumberOfJumps--;
                if (m_LastJump == 1)
                {
                    if (m_NumberOfJumps == 1)
                    {
                        m_NumberOfJumps = 0;
                    }
                }
                m_LastJump = m_NumberOfJumps;
                if (m_NumberOfJumps == 1)
                {
                    m_PlayerAudioManager.PlayJumpSound();
                }
                else
                {
                    m_PlayerAudioManager.PlayDoubleJumpSound();
                }

                m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, m_JumpStrength);
            }
        }
    }
    void SwitchState(AnimationStates nextState)
    {
        m_AnimationState = nextState;

        switch (m_AnimationState)
        {
        case AnimationStates.LANDING:
            m_PlayerAnimator.SetInteger("AnimationState", 7);

            // .
            // .
            // .

            landingParticleSystem.Play();
            // Sistema de partículas con polvillo...

            SwitchState(AnimationStates.RUNNING);
            break;


        case AnimationStates.RUNNING:

            m_IsDashing = false;
            m_IsSliding = false;
            m_IsTurning = false;


            //m_PlayerAnimator.SetInteger("AnimationState",0);
            m_MovementSpeed = m_OriginalMovementSpeed;
            //m_StartSliderTimer = false;
            RestartJumpsIfNeeded();

            break;

        case AnimationStates.JUMP:
            if (m_AvailableJumps == 2)
            {
                m_PlayerAudioManager.PlayJumpSound();
            }
            else if (m_AvailableJumps == 1)
            {
                m_PlayerAudioManager.PlayDoubleJumpSound();
            }
            m_AvailableJumps--;
            m_PlayerAnimator.SetInteger("AnimationState", 1);
            m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, m_JumpStrength);
            break;

        case AnimationStates.FALLING:
            if (m_IsGrounded)
            {
                SwitchState(AnimationStates.LANDING);
            }
            break;



        case AnimationStates.TURN:

            m_IsTurning = true;
            m_TurnTimer = 0;

            m_PlayerAnimator.SetInteger("AnimationState", 10);
            m_MovementSpeed = Vector2.zero.x;



            break;



        case AnimationStates.DASH:

            m_IsDashing = true;

            m_DashTimer     = 0;
            m_MovementSpeed = m_DashSpeed;
            break;



        case AnimationStates.SLIDE:

            m_IsSliding = true;
            m_PlayerAnimator.SetInteger("AnimationState", 2);

            m_SlideTimer       = 0;
            m_StartSliderTimer = true;

            break;
        }
    }
예제 #3
0
    private void Update()
    {
        //stunning state
        stunCounter -= Time.deltaTime;
        stunned      = stunCounter > 0;

        stunDecal.SetActive(stunned);

        if (blocking)
        {
            return;
        }
        if (!stunned)
        {
            if (spi.controller.XDown)
            {
                Block();
                Invoke("UnBlock", blockingTime);
            }
        }

        //grounded state
        Collider[] colliders = Physics.OverlapSphere(jumpCheckPoint.position, 0.1f, floorMask);
        grounded = colliders.Length > 0;

        //jumping
        if (grounded && spi.controller.ADown)
        {
            rb.AddForce(Vector3.up * jumpingForce, ForceMode.Acceleration);
            pAnim.TriggerJumpAnimation();
            pAudioManager.PlayJumpSound();
        }

        //Dashing
        dashCooldownCounter -= Time.deltaTime;
        dashCounter         -= Time.deltaTime;

        dashing = dashCounter > 0;

        if ((spi.controller.L1Down || spi.controller.L2Down) && dashCooldownCounter < 0.0f)
        {
            dashCooldownCounter = dashCooldown;
            dashCounter         = dashDuration;
            pAudioManager.PlayDashSound();
        }

        //Rock pickup
        if (holding && rockBody != null)
        {
            //Move with the player
            rockBody.MovePosition(transform.position + transform.forward * holdingDistance + Vector3.up * holdingHeight);
            rockBody.rotation = transform.rotation;
            rockBody.GetComponent <Collider>().enabled = false;
            rockBody.useGravity = false;

            //Throw the rock
            if (spi.controller.YDown)
            {
                StartCoroutine(this.ThrowRock());
                pAnim.TriggerThrowAnimation();
            }
        }

        if (spi.controller.BDown) // Pick up / put down
        {
            bool prevHolding = holding;
            if (holding && rockBody != null)
            {
                //drop the rock
                rockBody.GetComponent <Collider>().enabled = true;
                rockBody.useGravity = true;
                holding             = false;
            }
            else
            {
                Collider[] nearbyObjects = Physics.OverlapSphere(transform.position, pickupRange);

                for (int i = 0; i < nearbyObjects.Length; i++)
                {
                    if (nearbyObjects[i].tag == "Rock")
                    {
                        rockBody = nearbyObjects[i].GetComponent <Rigidbody>();
                        holding  = true;
                        break;
                    }
                    else if (nearbyObjects[i].tag == "Player" && nearbyObjects[i].GetComponent <PlayerController>().blocking&& nearbyObjects[i].gameObject != gameObject)
                    {
                        PlayerController otherPlayer = nearbyObjects[i].GetComponent <PlayerController>();

                        otherPlayer.rb.constraints = RigidbodyConstraints.None;
                        otherPlayer.beingHeldBy    = this;
                        otherPlayer.beingHeld      = true;

                        rockBody = nearbyObjects[i].GetComponent <Rigidbody>();
                        holding  = true;
                        break;
                    }
                }
            }

            if (prevHolding != holding)
            {
                pAnim.ToggleCarryAnimation();
            }
        }
    }