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

Input Key is unknown?

Discussion in 'Scripting' started by Denisowator, Jun 28, 2017.

  1. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    I have an if statement that unlocks the cursor in one script, and opens the pause menu in another. The cursor unlocks, but the pause menu doesn't open.

    Both scripts use the exact same line:
    Code (CSharp):
    1. if (Input.GetKeyDown ("cancel")) {
    The exact error it gives me is:
    upload_2017-6-28_11-39-55.png

    Any idea what's wrong?
     
    BMRG14 likes this.
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Point me to a cancel key. I don't have one.
     
  3. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    upload_2017-6-28_11-44-26.png

    It works if I use the "KeyCode" one, but I really wanna find out why this one isn't working.
     
    Last edited: Jun 28, 2017
  4. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    It works now. I'm gonna assume it's a bug.

    But the console is still spammed with that error, and it's coming from the first script (the one unlocking the cursor). Even though that one worked before, and still works.
     
  5. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    "Cancel" not "cancel"
     
  6. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    That doesn't matter.

    And just so you don't say it does, I just changed it, and this time if says "Cancel" instead of "cancel" in the error.

    EDIT: Doing "escape" instead of "cancel" works, don't know why cancel doesn't.

    EDIT 2: Just tested it with another one, like "Horizontal" and that doesn't work either... Shouldn't you have to call the axes instead of their keys? Isn't that the whole point of having the InputManager?

    What if I have multiple keys set up? it won't work for both of them this way.
     
    Last edited: Jun 28, 2017
  7. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You should be using GetButtonDown with the Input Manager, not GetKeyDown.

    "Cancel" vs "cancel" absolutely matters in that case.
     
  8. Denisowator

    Denisowator

    Joined:
    Apr 22, 2014
    Posts:
    918
    Oh, that's what I was doing wrong. Thanks. :)