Search Unity

How do I get Input Positive Button value in Runtime?

Discussion in 'Scripting' started by iprogrammer, Dec 26, 2016.

  1. iprogrammer

    iprogrammer

    Joined:
    Jan 4, 2015
    Posts:
    13
    In InputManager I assigned R Button to "Restart" name.
    Now "Restart" has key "Positive Button" and string value "R".


    Now in the game I can show notice to user: "click R for Restart!"
    But what if user will change that key in the start config window? For example from R to T.



    Game should display notice: "click T for Restart!"

    Question:
    How do I get changed Positive Button value by name "Restart" via script in Runtime? Is it possible?

    ---------------------------------------------
    p.s. in Editor I can do this:
    Code (CSharp):
    1.  
    2. SerializedObject inputManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
    3. SerializedProperty axisArray = inputManager.FindProperty("m_Axes");
    4.  
    5. for (int i = 0; i < axisArray.arraySize; ++i) {
    6.     var axis = axisArray.GetArrayElementAtIndex(i);
    7.     var axisName = axis.FindPropertyRelative("m_Name").stringValue;
    8.     if (axisName == "Restart") {
    9.         restartButtonValue = axis.FindPropertyRelative("positiveButton").stringValue;
    10.         break;
    11.     }
    12. }
    13.  
    But it allows to use it only in the Editor. Because it use UnityEditor.dll
     
    projeffboy likes this.
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
  3. iprogrammer

    iprogrammer

    Joined:
    Jan 4, 2015
    Posts:
    13
    Last edited: Dec 28, 2016
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,206
    They're working on a new input system. In the meantime, there are assets you can buy on the store.

    --Eric
     
unityunity