Unity new Input methods


Sun Aug 08 2021 20:46:52 GMT+0000 (UTC)

Saved by @thepapayaki #c#

// at top
using UnityEngine.InputSystem;

// update

private float strafeAmount = 0.0f;
void Update(){
  playerRb.AddForce(transform.left * strafeAmount * speed * Time.deltaTime); 

// Send Message events

// 1d axis event
private void OnStrafe(InputValue value){
  strafeAmount = value.Get<float>();

// button event
private void OnFire(){
  shoveInput = value.Get<float>();


1. Add 'Input System' via Package Manager 2. From Dialog, reboot with new Input System activated 3. Add new 'Input Actions' to project 4. Double-click it, and create new Actions (e.g. Fire, or Strafe). 'Button' for triggers. 'Value' for 1d or 2d axis. 5. On Player object, add new <PlayerInput> component. 6. Drag InputActions object into the 'Actions' spot on the new <PlayerInput> component 7. Keep Behavior to 'Send Messages' 8. Inside Player object's script .. add "using UnityEngine.InputSystem;" at top. 9. Inside Player object's script... use above code.