[ad_1]
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
15 times
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.
\$\endgroup\$
1
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 .
lang-cs
[ad_2]