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. Dismiss Notice

Using unity input for keyboard keys question

Discussion in 'General Discussion' started by Darkmyst, Jan 28, 2015.

  1. Darkmyst

    Darkmyst

    Joined:
    Aug 3, 2013
    Posts:
    35
    Hi, i feel really dumb right now because i feel like im missing something obvious, but lets say i want to assign a button to display a pause menu how would i go about that properly. If i just add a new input its like a control input, assigning a number to the input but i would just like a single boolean input with no positive or negative keys, just a key and an alt key. I don't really want to use input.GetKeyDown as that wont be a configurable key.
     
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  3. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,797
  4. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    I can second the use of CInput. It basically is the same as Unity's input, but the big deal is that you can modify inputs at runtime, and you can save the controls to different things besides only Unity's player prefs.
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    The InputManager makes everything look the same, but some of those properties are only relevant some of the time. If you call an input with GetAxis(inputName) then it treats it like an axis, with positive and negative range and such. If you call the same input with GetButton(inputName), however, it just returns a true or false depending on the current value, which is probably more what you're after.
     
  6. BlakeGillman

    BlakeGillman

    Joined:
    Dec 7, 2013
    Posts:
    412
    Input.GetKeyDown is plenty configurable. You have all the keys
    Then there is GetKeyUp
    GetKey
    and KeyCode, different things saying what type of key is being pressed, how long, or if there is a lack of pressing it, etc.

    Really it's not that hard:
    Here you go.

    (C#)

    Code (csharp):
    1.  
    2. if(Input.GetKeyDown("p") ) {
    3. toggleMenu();
    4. }
    5.  
    Put that in Update, make a Boolean controlling a gui.called "menu" or whatever.

    Then add a new void:

    Code (csharp):
    1.  
    2. void toggleMenu() {
    3. if(menu == false) {
    4.   menu = true;
    5.   return;
    6. }
    7. else if(menu == true) {
    8. menu = false;
    9. return;
    10. }
    11. }
    12.  
    That was typed straight In the reply box so its quality is not assured, but the general principal is there.
    Take from this and learn what you can. But next time you might also want to try and going on google..

    Click this link, I'll show you:
    http://bit.ly/1zED4Ll
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Unity missed something really obvious. Giving us the ability to configure input axis at run time. Its one of the few major failings of the engine. To get around it you'll need your own input manager.