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

(Solved) Disable all KeyCodes except the ones I want.

Discussion in 'Scripting' started by DarkTulip, Apr 2, 2016.

  1. DarkTulip

    DarkTulip

    Joined:
    Oct 21, 2014
    Posts:
    74
    Hi all,

    If the player hits a key, I want all other KeyCodes to be disabled except a few.
    If the player hits the same key again all other KeyCodes must be enabled again.

    Thank you.
     
  2. DarkTulip

    DarkTulip

    Joined:
    Oct 21, 2014
    Posts:
    74
    Can someone please help?
     
  3. HAlbera

    HAlbera

    Joined:
    Jun 7, 2013
    Posts:
    63
    Might I suggest using a bool and checking that when you check for input also?

    If you've got not many controls that would be easiest.

    If you have many, you might look into a state machine for your controls?
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Put all of your calls to Input.GetXXX inside of a single class. Use this class as a layer of abstraction between you code and Input. In this abstraction layer you can do stuff like disable all input.
     
    metamorphist and HAlbera like this.
  5. HAlbera

    HAlbera

    Joined:
    Jun 7, 2013
    Posts:
    63
    Thats a neat idea, never thought of that!
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    It also works well for building runtime configurable input.
     
  7. DarkTulip

    DarkTulip

    Joined:
    Oct 21, 2014
    Posts:
    74
    Thank you for your reply. Time for me to wrestle with Input.GetXXX. Up to the manual.
     
  8. DarkTulip

    DarkTulip

    Joined:
    Oct 21, 2014
    Posts:
    74
    I think I managed it. Thanks a lot.