- Home /
How does the new input system work?
I decided to try the new input system and it immeadilty hit me in the face like the air from a car air condioner on a summer day just after you turn it on. I understood none of it, but managed to figure out a basic Action Map. But I have no clue how to connect it up or advance apon it. I have an action map 'Player' and the actions 'Move' and 'Fire', but my attempts to hook everything up have not been successful. I have tried in the Player Input thing and in the script itself, but it won't work.
same thing bro, i havent understand a single thing about the new input system
Answer by andrew-lukasik · Aug 30, 2020 at 03:41 PM
New Input system is confusing at first because it allows multiple ways of doing the same thing in very different ways. One of those methods mirrors old syntax a lot, take a look :
OLD:
if( Input.GetKeyDown(KeyCode.Space) )
Debug.Log("old input system, space key pressed");
NEW:
using UnityEngine.InputSystem;
var keyboard = Keyboard.current;
if( keyboard.spaceKey.wasPressedThisFrame )
Debug.Log("NEW INPUT SYSTEM, space key pressed");
See? Pretty much the same! Ignore Action Map
s and other methods for now. This is probably more that enough for prototypes and simple projects.
mouse:
var mouse = Mouse.current;
Vector2 mousePosition = mouse.position.ReadValue();
if( mouse.leftButton.wasPressedThisFrame )
Debug.Log($"NEW INPUT SYSTEM, LMB pressed\t( x:{mousePosition.x} , y:{mousePosition.y} )");
if( mouse.rightButton.wasPressedThisFrame )
Debug.Log($"NEW INPUT SYSTEM, RMB pressed\t( x:{mousePosition.x} , y:{mousePosition.y} )");