playerCharacter.Update C# (CSharp) Method

Update() protected method

protected Update ( ) : void
return void
    protected override void Update()
    {
        //Grounded movement
        moveH = Input.GetAxisRaw("Horizontal");
        Flip(moveH);
        if (IsGrounded()) {
            if (moveH > 0)
            {
                characterAnimator.SetBool("Run", true);
                if (rb.velocity.x < 0) rb.velocity = new Vector2(0, rb.velocity.y);
                rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
            }
            else if (moveH == 0) characterAnimator.SetBool("Run", false);
            else if (moveH < 0)
            {
                characterAnimator.SetBool("Run", true);
                if (rb.velocity.x > 0) rb.velocity = new Vector2(0, rb.velocity.y);
                rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
            }
        }

        //Jumpstate handler
        switch (jumpState) {
            case JumpStates.GROUNDED:
                if ((Input.GetKey(KeyCode.Space) || Input.GetAxis("LTrig") > 0.1) && IsGrounded())
                {
                    jumpState = JumpStates.JUMPING;
                    characterAnimator.SetBool("Jump", true); //Switch to jump animation
                    characterAnimator.SetBool("Hit", false);
                }
                break;

            case JumpStates.JUMPING:
                if ((Input.GetKey(KeyCode.Space) || Input.GetAxis("LTrig") > 0.1) && currentJumpForce < maxJumpForce)
                {
                    applyJumpForce = true; //Adds force in fixed update
                }
                else
                {
                    jumpState = JumpStates.FALLING;
                    currentJumpForce = 0;
                    applyJumpForce = false;
                }
                break;

            case JumpStates.FALLING:

                if (IsGrounded() && rb.velocity.y <= 0)
                {
                    //Debug.Log("Grounded"); Use this to debug jump issues
                    jumpState = JumpStates.GROUNDED;
                    characterAnimator.SetBool("Jump", false); //End jump animation
                }
                break;
        }

        //If player runs out of health or falls below
        if((currentHealth <= 0f || transform.position.y < -5f) && !alreadyDying){
            alreadyDying = true;
            StartDeath();
        }
    }