Untitled
unknown
plain_text
9 months ago
1.3 kB
5
Indexable
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using static UnityEngine.InputSystem.DefaultInputActions;
[CreateAssetMenu(fileName = "New Input Reader", menuName = "Input/Input Reader")]
public class InputReader : ScriptableObject, IPlayerActions
{
public event Action<bool> JumpEvent;
public event Action<bool> MoveEvent;
private DefaultInputActions controls;
private void OnEnable()
{
if(controls != null)
{
controls = new DefaultInputActions();
controls.Player.SetCallbacks(this);
}
controls.Player.Enable();
}
public void OnFire(InputAction.CallbackContext context)
{
}
public void OnLook(InputAction.CallbackContext context)
{
}
public void OnMove(InputAction.CallbackContext context)
{
MoveEvent?.Invoke(context.ReadValue<Vector2>());
}
public void OnJump(InputAction.CallbackContext context)
{
if (context.performed)
{
JumpEvent?.Invoke(true);
}else if (context.canceled)
{
JumpEvent?.Invoke(false);
}
}
}
Editor is loading...
Leave a Comment