コード例 #1
0
 // responsible for the stamina verification and consuption
 private int staminaUse(float amount)
 {
     if (staminaBar.EnoughStamina())
     {
         staminaBar.UseStamina(amount);
         return(0);
     }
     return(1);
 }
コード例 #2
0
    private void Move()
    {
        bool clicado;

        // Running
        if (Input.GetKey(KeyCode.LeftShift))
        {
            clicado = true;
            {
                if (direction.x != 0 && onGround)
                {
                    if (staminaBar.EnoughStamina() && clicado)
                    {
                        staminaBar.UseStamina(runStaminaCost);
                        rb.velocity = new Vector2(direction.x * runSpeed, rb.velocity.y);
                    }
                    else
                    {
                        clicado = false;
                    }
                }
            }
        }
        // Walking
        else
        {
            rb.velocity = new Vector2(direction.x * walkSpeed, rb.velocity.y);
        }

        if ((direction.x > 0 && !facingRight) || (direction.x < 0 && facingRight))
        {
            Flip();
        }
    }
コード例 #3
0
ファイル: JumpController.cs プロジェクト: SWE3T/Bright
 private void Jump()
 {
     if ((Input.GetButtonDown("Jump")) && onGround)
     {
         CreateDust();
         rb.velocity = new Vector2(rb.velocity.x, 0);
         if (staminaBar.EnoughStamina())
         {
             staminaBar.UseStamina(jumpStaminaCost);
             rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
         }
     }
     // is going up and jump button is still pressed
     else if ((Input.GetButton("Jump")) && !onGround && (rb.velocity.y > .1f))
     {
         if (staminaBar.EnoughStamina())
         {
             staminaBar.UseStamina(jumpStaminaFactor);
         }
     }
 }