Search Unity

Question How check which button for same action

Discussion in 'Input System' started by NamelessGames_, Jan 3, 2023.

  1. NamelessGames_

    NamelessGames_

    Joined:
    Jun 4, 2019
    Posts:
    43
    Hi,

    I have a Build action who change my current action map from "Player" to "Build".

    When it changes, I would like make a an action into "Build (Action Map)" with multiple input keys.
    Buildings prefabs should have a string with letter of his shortcut. For example, when user presses "B" (Build) and then "P" it should build "Palace".

    How should I do? I wouldn't like make an action for everyone Building, just Bindings.

    I hope it's clear my question.

    upload_2023-1-3_18-30-31.png
     
  2. NamelessGames_

    NamelessGames_

    Joined:
    Jun 4, 2019
    Posts:
    43
    To people who could have same question:

    Code (CSharp):
    1. int nBuildActions = _input.Build.BuildAction.controls.Count;
    2. for (int i = 0; i < nBuildActions; i++)
    3. {
    4.     InputControl control = _input.Build.BuildAction.controls;
    5.     if (control.IsPressed())
    6.     {
    7.         control.name; // this is the name of action. IE: "F [Keyboard]" would be "f"
    8.         break;
    9.     }
    10. }