Untitled

 avatar
unknown
plain_text
a month ago
1.3 kB
3
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);
        }
    }
}
Leave a Comment