need help fon changing a variable in an other script using the argument of a function

The title might be confuse but here is what I am trying to do :

    public void SetNewKey(string keyName)
    {
        newKey = KeyCode.None;
        isChangingKey = true;
        InputManager.IM.keyName = KeyCode.None;
        changingKeyName = keyName;

    }

I want to acces the variable of the InputManager that has the same name as the keyName I give with the SetNewKey fonction.

I know this is not the way to do it because I got the error CS1061: ‘InputManager’ does not contain a definition for ‘keyName’ and no accessible extension method ‘keyName’ accepting a first argument of type ‘InputManager’ could be found (are you missing a using directive or an assembly reference?).

I just don’t know how to do this.

It would help if you shared your InputManager code. But basically it seems like there is no public “keyName” member on InputManager.

1 Like

Yes there is no such name, because I want to take the name I give in the function SetNewKey.

Here is the code :

public class InputManager : MonoBehaviour
{

    public static InputManager IM;

    public KeyCode forward;
    public KeyCode backward;

    void Awake()
    {
        // vérifier qu'il y ait pas 2 InputManager
        if(IM == null)
        {
            DontDestroyOnLoad(gameObject);
            IM = this;
        }
        else if(IM != this)
        {
            Destroy(gameObject);
        }


//chopper les touches enregistrées avant
        forward = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("forward", "W"));
        backward = (KeyCode) System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("backward", "S"));
    }

The objective is to do the folowing thing :

if y use SetNewKey(forward) it changes the forward keycode in the input manager directly.