Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Write KeyCode value to file and then use

Discussion in 'Scripting' started by Constantyne, Jan 22, 2022.

  1. Constantyne

    Constantyne

    Joined:
    Aug 20, 2020
    Posts:
    2
    Hello. Do any of you know what is the best way to store the KeyCode values in a document (jsn, xml ...) and then get it back to use. I managed to convert the KeyCode to a string:

    Code (CSharp):
    1. Convert.ToString(code)
    Next, I already use the value of the string in InputGetKey(). But I ran into a problem and in order for the value of the string to be correctly interpreted, I use ToLower() for the string, but the question is, will this work with all keys?
     
  2. Putcho

    Putcho

    Joined:
    Jun 1, 2013
    Posts:
    246
    so you pass a raw string into InputGetKey()? why not covert back to enum using
    Enum.TryParse("text", out KeyCode myStatus) you can give it a try
     
    Constantyne likes this.
  3. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    I would even use the int value directly (if you are not dependent on "reading" your textfile visually). You can cast int to enum. If you use .ToLower you cannot parse the enum back.
     
    Constantyne and Bunny83 like this.