Search Unity

Input not found?

Discussion in 'Scripting' started by Spidyy, Mar 14, 2011.

Thread Status:
Not open for further replies.
  1. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Heya.

    I got a problem.

    I defined an input in the Project Settings -> Input, named "Fire".

    The input in made like that :

    Code (csharp):
    1. Name : Fire
    2. Positive Button : w
    3. Alt Positive Button : joystick button 0
    4. Gravity : 1000
    5. Drad : 0.001
    6. Sensitivity : 1000
    7. Snap : false
    8. Invert : false
    9. Type : Key or Mouse Button
    10. Axis : X acis
    11. Joy Num : Get Motion from all Joysticks
    I made a player script in wich I use this code :

    Code (csharp):
    1.         if(Input.GetKeyDown("Fire"))
    2.         {
    3.             Debug.Log("bang");
    4.             FireMachinegunBullet(myTransform.localPosition);
    5.         }
    But when I'm launcher the simulation, the log tel me:
    Code (csharp):
    1. UnityException: Input Key named : Fire is unknown
    Do anyone encountered the same issue and got a solution?
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Check the docs for GetKeyDown() (and related functions) and GetButtonDown() (and related functions). These two sets of functions do different things.
     
    carl-ukiyo-studio and KVenk like this.
  3. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    MoltenTears and fabioj like this.
  4. AngryBear+^

    AngryBear+^

    Joined:
    Apr 4, 2009
    Posts:
    68
    Use Input.GetButtonDown() rather than Key. Input.GetKey/Input.GetKeyDown is specifically for keys on your keyboard. The "Button" commands pertain to your input buttons.
     
    KVenk and Tom_Green like this.
  5. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Thanks, it work now. :]
     
  6. carl-ukiyo-studio

    carl-ukiyo-studio

    Joined:
    Oct 18, 2022
    Posts:
    1
    Thank you brother.
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    In the future, please use the like button instead. You've just necrod an 11 year old post.

    Thanks.
     
Thread Status:
Not open for further replies.