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.

Question How to display single composite value instead of full W/A/S/D ??

Discussion in 'Input System' started by valentin56610, Aug 10, 2023.

  1. valentin56610


    Jan 22, 2019
    Good evening!

    Question is simple, I can't find a way to only display only one part of a composite axis

    I am doing a binding menu for my game and I want each part of the composite to be rebinded individually, that works.

    But now, when it comes to displaying the information, I do this:
    Code (CSharp):
    1. _keyName_text.text = _inputAction.GetBindingDisplayString(0, InputBinding.DisplayStringOptions.DontUseShortDisplayNames);
    But for some reason it will only display the full thing, and that's not what I want since I'm rebinding individually (Forward, Backward, Left, Right).

    For now, I'll go with parsing the results from 'GetBindingDisplayString()', and since I know which index of the composite axis I am accessing, I can count the amount of '/' and simply take the character before it

    But is there some other solution? I mean, there is not a single game I played in my life that does that kinda of weird rebinding 4 axis at a time...
  2. valentin56610


    Jan 22, 2019
    Thought I'd share the code to retrieve a unique letter or group of letters between slashes based on index:

    Code (CSharp):
    1.     string GetStringAtIndex(int p_index, string p_input)
    2.     {
    3.         string[] parts = p_input.Split('/');
    5.         if (p_index >= 0 && p_index < parts.Length)
    6.         {
    7.             string selectedPart = parts[p_index];
    9.             if (selectedPart.Length > 0)
    10.             {
    11.                 char selectedChar = selectedPart[0];
    13.                 return selectedChar.ToString();
    14.             }
    15.             else return "Invalid part";
    16.         }
    17.         else return "Invalid index";
    18.     }