Hi,
I am stuck on this thing and cannot quite figure a workaround.
I have a struct:
public class Keys
{
public string keyName;
public KeyCode keyCode;
public KeyCode keyCodeName;
public Keys(string keyName, KeyCode keyCode, KeyCode keyCodeName)
{
this.keyName = keyName;
this.keyCode = keyCode;
this.keyCodeName = keyCodeName;
}
}
I have a list of variables:
public static KeyCode UserKeyUpPrimary;
public static KeyCode UserKeyDownPrimary;
public static KeyCode UserKeyLeftPrimary;
public static KeyCode UserKeyRightPrimary;
I have a list of these variables:
public List<Keys> keys = new List<Keys>();
keys.Add(new Keys("Up", KeyCode.W, UserKeyUpPrimary));
keys.Add(new Keys("Down", KeyCode.X, UserKeyDownPrimary));
keys.Add(new Keys("Left", KeyCode.A, UserKeyLeftPrimary));
keys.Add(new Keys("Right", KeyCode.D, UserKeyRightPrimary));
When I try to write to the variable inside the list like this, it doesn’t work:
//Assign the key bind to the variable
keys[i].keyCodeName = (KeyCode)PlayerPrefs.GetInt("KeyBind" + keys[i].keyName);
When I write like this, it does work:
//Assign the key bind to the variable
UserKeyUpPrimary = (KeyCode)PlayerPrefs.GetInt("KeyBind" + keys[i].keyName);
How can I call the variable KeyCode inside the list and assign a KeyCode to it without calling it by name?
Thank you