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

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:
    31
    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:
    31
    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. }