- Home /
How to set KeyCode with Number for load? C#
ok I'd like to find out if I give number 97 what KeyCode will I get not the otherway around
function that works now
public KeyCode[] keyControllKeyCode = new KeyCode [50];
void SaveData(){
PlayerPrefs.SetInt("asdf",(int)KeyCode.A);
using(var writer = new BinaryWriter(File.OpenWrite("c:/Programming/asdf.txt"))){
writer.Write((int)KeyCode.A);
writer.Close();
}
}
void LoadData(){
keyControllKeyCode[0] = (KeyCode)PlayerPrefs.GetInt("asdf");
using(var reader = new BinaryReader(File.OpenRead("c:/Programming/asdf.txt"))){
keyControllKeyCode[10] = (KeyCode)reader.ReadInt32();
reader.Close();
}
}
any way I would like to convert integer back in to keycode like I'm trying with KeyCode whatever
I'm kinda bad in enums and read around 7 articles and Q/A and just can't get a grip
from all that I've managed in around 4 hours to get KeyCode in to int
thanks in advance
Answer by Loius · Feb 12, 2013 at 08:54 PM
I'm saying I don't get it
public $$anonymous$$eyCode[] keyControll$$anonymous$$eyCode = new $$anonymous$$eyCode [50];
$$anonymous$$eyCode keyControll$$anonymous$$eyCode[1] = ($$anonymous$$eyCode)97;
Assets/Scripts/$$anonymous$$ain$$anonymous$$enu.cs(237,17): error CS0650: Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type
To add the actual example:
selectedi = ($$anonymous$$eycode)reader.ReadInt32();
or
$$anonymous$$eyCode whatever = ($$anonymous$$eyCode)PlayerPrefs.GetInt("asdf", (int)$$anonymous$$eyCode.A);
I've passed "A" as default value.
gr8 thanks Bunny83
you can change your comment to an answer as it works
didn't know tho that $$anonymous$$eyCode has to be in front of 2. example even if that was declared before
Your answer
Follow this Question
Related Questions
Converting string of a key into KeyCode 2 Answers
Cast the result of an enum as a string 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers