Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need help with disabling a key input.

Discussion in 'Editor & General Support' started by calebbecker5, Aug 1, 2013.

  1. calebbecker5

    calebbecker5

    Joined:
    Jul 26, 2013
    Posts:
    1
    function Update (){
    if (Input.GetKeyDown("1")){
    healthPot ();
    }


    function healthPot (){
    health += healthPotion;
    healthPotionAmount --;
    Debug.Log( healthPotionAmount + " health potion reamaining.");


    }

    I want to make it so when the amount of health potions reach 0, it will disable the ability to use the keyboard input, or something close to that.
     
  2. Avalion

    Avalion

    Joined:
    May 2, 2012
    Posts:
    34
    Why not simply do

    function healthPot() {
    if (healthPotionAmont > 0) {
    health += healthPotion;
    healthPotionAmount --;
    }
    }