Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sdgd · Feb 12, 2013 at 08:07 PM · c#convertenumsaveloadkeycode

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Karsnen_2 · Feb 12, 2013 at 08:42 PM 0
Share

Even I have stuck with this many a times.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Loius · Feb 12, 2013 at 08:54 PM

http://stackoverflow.com/questions/29482/cast-int-to-enum-in-c-sharp

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Feb 12, 2013 at 09:01 PM 0
Share

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
avatar image Bunny83 · Feb 12, 2013 at 09:02 PM 1
Share

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.

avatar image sdgd · Feb 12, 2013 at 09:11 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Convert String into KeyCode (UnityScript) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges