Search Unity

Input.GetButton() returning true when I don't want it to

Discussion in 'Scripting' started by nesseggman, Mar 4, 2015.

  1. nesseggman

    nesseggman

    Joined:
    Dec 20, 2012
    Posts:
    22
    I have a menu in which pressing the 'submit' input over a Button will restore control to the player and put an item in the player's hands. After regaining control, the player can press the 'submit' input to use the item (not meant to be used right away, but the next time the player presses 'submit')

    The problem is that this is that Input.GetButton("Sumbit") is returning true to select the menu item, and then immediately to use the item in the player's hands, because the control is returned to the player character object as soon as the button is clicked, and GetButton hasn't changed back to false yet. I don't want the player to use the item yet until the next GetButton("Submit") but I don't know how to do this.

    I've come across this before and done some kind of stupid workarounds, but I feel like this would probably be a common problem, but I'm not sure how to search for it or what to refer to it to. How do people normally solve this problem?

    I realize this is probably a beginner thing, but I'm a beginner. Thanks so much for the help.
     
  2. CastleIsGreat

    CastleIsGreat

    Joined:
    Nov 10, 2014
    Posts:
    176
    I'd suggest Looking at the differences between GetButton and GetButtonDown. (I think what you're getting at is that you want it to be a once per click kinda function, and not to update the next frame while the player is still pressing down the submit button from the first command).
     
    nesseggman likes this.
  3. nesseggman

    nesseggman

    Joined:
    Dec 20, 2012
    Posts:
    22
    Ah, thanks, it really was that simple. I actually had completely misunderstood GetButton but didn't think to double-check it. I've been thinking of it wrong all this time! Thanks for answering and sorry for such a noob question :p
     
  4. CastleIsGreat

    CastleIsGreat

    Joined:
    Nov 10, 2014
    Posts:
    176
    No such thing as a noob question, I surf the forums to answer questions and learn along the way, Sometimes I have no idea what is going on. Most times I learn something too.
     
    nesseggman likes this.