(Unity 3D) Как запретить игроку нажимать на клавишу?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class StaminaScript : MonoBehaviour
{
    public Image staminaBar;
    public float maxStamina = 100f;
    public float currentStamina;
    public float staminaDecreaseSpeed = 15f;
    public float staminaRecoverSpeed = 5f;
    private bool isRecoveringStamina;
    private float noRecoveryTimer;
    private void Start()
    {
        currentStamina = maxStamina;
        UpdateStaminaBar();
    }
    
    private void Update()
    {
        if (Input.GetKey(KeyCode.LeftShift) && currentStamina > 0f)
        {
            currentStamina -= staminaDecreaseSpeed * Time.deltaTime;
            UpdateStaminaBar();
            if (currentStamina <= 0f)
            {
                noRecoveryTimer = 5f;
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.LeftShift) && currentStamina <= 0f)
            {
                // Ничего не делаем
            }
            else
            {
                if (currentStamina < maxStamina)
                {
                    if (currentStamina > 0f && noRecoveryTimer <= 0f)
                    {
                        isRecoveringStamina = true;
                    }
                    else
                    {
                        isRecoveringStamina = false;
                        currentStamina = Mathf.Clamp(currentStamina, 0f, maxStamina);
                        UpdateStaminaBar();
                    }
                }
            }
        }
        
        if (isRecoveringStamina)
        {
            currentStamina += staminaRecoverSpeed * Time.deltaTime;
            UpdateStaminaBar();
            
            if (currentStamina >= maxStamina)
            {
                isRecoveringStamina = false;
                currentStamina = maxStamina;
                UpdateStaminaBar();
            }
        }
        
        if (noRecoveryTimer > 0f)
        {
            noRecoveryTimer -= Time.deltaTime;
            
            if (noRecoveryTimer <= 0f)
            {
                currentStamina = Mathf.Clamp(currentStamina, 0.1f, maxStamina);
                UpdateStaminaBar();
            }
        }
    }
    
    private void UpdateStaminaBar()
    {
        staminaBar.fillAmount = currentStamina / maxStamina;
    }
}

Мой код на добавление стамины в Unity3D, не могу придумать как запретить игроку нажимать на клавишу LShift, если значение стамины <= 0

В качестве модели игрока использую Mini First Person Controller (Default Asset)

P's - Я полный новичок в C# и Unity, большую часть кода писал с большой помощью нейронок


Ответы (0 шт):