#make a inventory select feature (press 1'2'3'4'5'6...) like minecraft with new Inputsystem
1 messages ยท Page 1 of 1 (latest)
I don't know what u doing there, but the easiest way to check which key you pressed is:
//Do something. You can change the Keycode to anything else, like num buttons
}```
Hope this helps. As always **GL and HF**! 
This approach uses the old input system, and it seems the OP is using the "new" input system package, there are 2 ways input is handled in Unity, through the Input class as you have in your example, and through an Input Action Asset, as they have in their screenshot, so sadly this approach wont work for them, unless they are using "both" as their input handling option in their project settings
Though I think the easiest way to achieve this using the "new" input system is to simply make a "UseTool1", "UseTool2" etc and bind to those actions, if you did want to use just 1 action, you may have to find out which binding was specifically pressed through the CallbackContext of the function you subscribe "UseTool" to - here are the docs for CallbackContext: https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.InputSystem.InputAction.CallbackContext.html?q=CallbackContext
Oh, i see, but this "new" input system isn't availble on my version of unity, that's why i didn't know anything about it...
I think this should give you an error in case you're creating a C# class from those input actions since their name is a number, kind of like when naning variables they cannot start with a number. Try changung your naming rules (for example: instead of 1, name it Tool1).
However, if unity is smart and handles these situations your input action in code should be calles @1, which is a C# solution for when people use invalid words for variable namings, such as callins a variable new for example.
If you are using 2018.3+ it should be something you can install from the Package Manager, albeit, different versions of the Input System will be available in newer versions of the editor though, and it is something that takes time to get familiar with so not everyone is aware of it or even needs all of what it offers, till a project deals with controllers or multi-input, binding or other forms of input thats harder to do with the Input class alone
the 1 you mean is (1[keyboard]) ?
1 isn't it's name. 1 is the keycode
Oh right, my bad. I think you can access the pressedKey from the fired event. Gotta check it real quick.
๐ค
i think i will try this. because i don't know how to get the keycode in multiple binding. set multiple action is the quick way to get what i want.
I've found here you can cast the control property into a KeyControl, which allows you to access the KeyCode.
oh
I personally would avoid doing this since you already have the presses and canceled event for those.
Assuming you generated a C# class from your input actions asset, of course.
Yeah I didn't know you could do that eithee ๐ , really cool to know. Haven't tested it tho but hopefully it works if you end up trying it out.
pog
you mean WasPressedThisFrame(); ?
Yeah, basically I mean that if you make a C# class, each input action fires performed, canceled and started events. I assume that loop behaviour you've done is already implemented, maybe more optimized in some way.
Cool to see it really works btw!
why i put them in Update 
I mean that works fine aswell and it wont impact performance at all, so you shouldn't worry.
oh ok thx : D
