Okay so I'm trying to make a system that picks a random word then it turns that word into a char array. Then it will track if you type the characters. But the method that I'm trying to do hasn't been working. mainly because it won't let me use a variable name as a keycode. Is this a worthwhile problem, or should I abort mission and try something else.
string currentWord = wordArray[Random.Range(0, typingWords.Length)];
char[] wordAsArray = currentWord.ToCharArray();
Keycode currentLetter = wordAsArray[0];
if (Input.GetKey(currentLetter))
{
Debug.Log("Test");
}
most of this works fine but what doesn't work the problem is the if (Input.GetKey(currentLetter))
is there something that can turn the word into a KeycodeArray or something like that or turn the specific character into keycode.
Does anybody know if this problem is solvable or will I have to use another method.
is there something that can turn the word into a KeycodeArray or something like that or turn the specific character into keycode.There is not a built-in function for that. You can create a keycode array with each keycodes in it and use that to determine current letter. Like:
'A' is subtracted from it to get the index of the letter in the letterCodes array. This assumes that the word only contains uppercase letters.
Instead of that method i would use a different approach. I will write down a complete example of how i would do it with comments.
GetNextKeyCodemethod converts the next letter in the word to a KeyCode value by converting the letter to uppercase and using System.Enum.Parse to look up the corresponding KeyCode value.GetKeyPressedmethod checks which key was pressed and returns the corresponding KeyCode value by looping over all possible KeyCode values and checking which one has been pressed using Input.GetKeyDown.