Skip to content

Instantly share code, notes, and snippets.

@inertiave
Created September 23, 2019 02:40
Show Gist options
  • Save inertiave/1082b5878d4f1766ba8c605a8b375174 to your computer and use it in GitHub Desktop.
Save inertiave/1082b5878d4f1766ba8c605a8b375174 to your computer and use it in GitHub Desktop.
New Input System
using UnityEngine;
using UnityEngine.InputSystem;
namespace MyNamespace {
public class PlayerMovement : MonoBehaviour, MyControl.IMovementActions {
public MyControl control;
void Awake()
{
control = new MyControl();
control.Movement.SetCallbacks(this);
}
void OnEnable()
{
control.Movement.Enable();
}
void OnDisable()
{
control.Movement.Disable();
}
void Update() { }
public void OnJump(InputAction.CallbackContext ctx)
{
if (ctx.performed) {
Debug.Log("Jumped");
}
}
public void OnInteraction(InputAction.CallbackContext ctx)
{
if (ctx.started) {
Debug.Log("Started");
} else if (ctx.canceled) {
Debug.Log("Canceled");
} else if (ctx.performed) {
Debug.Log("Performed");
}
}
public void OnScroll(InputAction.CallbackContext context)
{
if (context.performed) {
var value = context.ReadValue<float>();
Debug.Log(value);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment