#like this

1 messages · Page 1 of 1 (latest)

quaint terrace
#

Unity's KeyCode is an enum, which means that under the hood it's just a fancy way to give names to a bunch of numbers.

If you know which numbers are associated with the names you're interested in (alphabet keys for you, I assume?), you can generate a random number that fits them, and then cast (transform) it into the enum to get a value you can use - That's what Dalphat's answer is showing you.

This cool gist has a bunch of values for Unity's keycodes, I hope that helps you figure it out 🙂 https://gist.github.com/Extremelyd1/4bcd495e21453ed9e1dffa27f6ba5f69

Gist

Unity keycode values. GitHub Gist: instantly share code, notes, and snippets.

wanton junco
#

Thanks, So how do i call the enum

#

I dont think it like it

quaint terrace
#

Just a heads-up for next time, in #854851968446365696 it mentions "Do not share screenshots of code unless requested."

wanton junco
#

Ah sorry

quaint terrace
#

It looks like you're not casting your number to a KeyCode. Casting between types looks like this: (int)2.5f, which casts a float into an int

wanton junco
#

Im struggling on how to get the values out

quaint terrace
wanton junco
#

So would it be if (Input.GetKey(KeyCode(110)))

quaint terrace
#

Your current code looks like you're giving 110 as a parameter / argument to KeyCode - like KeyCode(110).

Instead, you should cast the int to your enum - that would look like: (KeyCode)110

#

I know that they're pretty similar, so it's not easy to spot at a glance 😅

wanton junco
#

Sorry only sending a screen shot because it flags as an error

quaint terrace
#

The error message looks like it's confused because it doesn't know what KeyCode "means".

Do you have a variable or method defined in your script that is also called KeyCode?

wanton junco
#

No just the standard original KeyCode from unity

quaint terrace
#

Hm. Is BattleManager something from your project?

wanton junco
#

thats the class im workingg on

quaint terrace
#

Are you sure there's nothing in that script / file called KeyCode, except from the part in Input.GetKey?

wanton junco
#

Only the enum

#

public enum KeyCode

quaint terrace
#

Ok, so yeah, you've defined a new KeyCode enum. You don't need to do that, Unity already has one

#

The error is because Unity doesn't know which KeyCode (its own, or your new one) you mean when you write (KeyCode)110 - but that looks right otherwise.

wanton junco
#

Ok im getting confused haha, So this

#
    {
        A = 97, // 0x00000061
        B = 98, // 0x00000062
        C = 99, // 0x00000063
        D = 100, // 0x00000064
        E = 101, // 0x00000065
        F = 102, // 0x00000066
        G = 103, // 0x00000067
        H = 104, // 0x00000068
        I = 105, // 0x00000069
        J = 106, // 0x0000006A
        K = 107, // 0x0000006B
        L = 108, // 0x0000006C
        M = 109, // 0x0000006D
        N = 110, // 0x0000006E
        O = 111, // 0x0000006F
        P = 112, // 0x00000070
        Q = 113, // 0x00000071
        R = 114, // 0x00000072
        S = 115, // 0x00000073
        T = 116, // 0x00000074
        U = 117, // 0x00000075
        V = 118, // 0x00000076
        W = 119, // 0x00000077
        X = 120, // 0x00000078
        Y = 121, // 0x00000079
        Z = 122, // 0x0000007A
    }```
#

is wrong and i dont need to use that? or i dont need to use the name of the enum

quaint terrace
#

You don't need that at all.

#

Sorry, I wasn't clear.

#

When I sent you the link, I didn't mean 'use this directly' - I meant someone has already written down which Unity KeyCode is which number, so you had some help figuring out which numbers to generate.

#

For example, if you wanted to generate a number key (known as Alpha- something in KeyCode), you would generate a number between 48 and 57

#

Then, you can cast that number into a KeyCode to use with your Input check

wanton junco
#

Haha i fully understand now, many thanks jowr

#

Sorry one more question can i reverse that

#

blockLetter.text = ;

#

can i set the text to be the random int value but in string form i.e if 110 was casted could i convert that to Get the letter N in return so then the text on the screen would say "N"

quaint terrace
wanton junco
#

Thanks awsome thanks