\$\begingroup\$

So I have no idea if there is a way to do this, but I’m trying to find a way to turn an alpha number in a game object name string into an Alpha key code.
Heres my code:

slot = transform.parent.parent.name;
refinedSlot = slot[11];
keySlot = KeyCode.Alpha/*refinedSlot*/;

Thanks in advance. I also know that refinedSlot is probably useless, but I added it in case it might be usefull.

Daniel Kim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

\$\endgroup\$

1

\$\begingroup\$

If slot is a string then slot[11] is one character of this string and is of type char.

Fortunately the digits in the Keys Enum (not KeyCode) have the same integer value as the corresponding characters. Therefore, we can simply cast the character to this Keys enum.

string slot = transform.parent.parent.name;
char refinedSlot = slot[11];
Keys keySlot = (Keys)refinedSlot;

\$\endgroup\$

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged .