- Home /
Is there a way to get currently pressed anything In new Input System
Basically something like Input.Any . I am trying to get currently used device so i want to get pressed input on it and then record that device into the list .That way i could then sort by index which player needs to get proper device based on when he pressed said input.
Answer by dorusoftware · Apr 16, 2021 at 01:31 AM
I think the way it should work is to create controls for each of the devices you will support in the game.
so you have keyboard and mouse, gamepad and mobile touch. each of these will have different inputs but that they will call the same fuction in the game.
So if you have FIreWeapon
then on the keyboard and mouse you put the mouse button
on gamepad you put button x
on touch you put whatever touch button needs to fire the weapon.
this way you decouple the user input from the gamelogic.
should select the input device automatically or even have them at the same time on, like on windows where both keyboard and the game pad works and you can switch between them in games
Yes it seems that's the way it's supposed to work. After i got an action from the InputActionAsset all I needed to do was just add method to performed delegate in it . With this i could map the devices in the order they were added in, and i could unregister them too!
private void Awake()
{
Inputs.actionMaps[0].FindAction("Jump").performed += RegisterDevice;
}
private void RegisterDevice(InputAction.CallbackContext context)
{
var myDevice = context.control.device;
if (!devices.Contains(myDevice))
{
devices.Add(myDevice);
playerInputDevicesText[devices.IndexOf(myDevice)].text = $"Connected on {myDevice.name}";
}
}