summaryrefslogtreecommitdiff
path: root/Assets/Scripts/GameControllerInput.cs
blob: ff29c1231260dedd9a971c83fcddce24ed9eb48c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(PlayerControl))]
public class GameControllerInput : MonoBehaviour
{
    private PlayerControl _playerControl;
    
    private void Awake()
    {
        _playerControl = GetComponent<PlayerControl>();
    }
    
    public void OnMove(InputAction.CallbackContext context)
    {
        Vector2 input = context.ReadValue<Vector2>();
        _playerControl.movementHorizontal = input.x;
        _playerControl.movementVertical = input.y;
    }

    public void OnGrab(InputAction.CallbackContext context)
    {
        float value = context.ReadValue<float>();
        bool isGrabbing = value > 0.5f;
        _playerControl.grabbing = isGrabbing;
    }
}