fgm24/Assets/Scripts/Player/Input/PlayerInput.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2024-02-03 16:21:32 +01:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEngine;
using UnityEngine.InputSystem;
2024-03-01 19:44:22 +01:00
public class PlayerInput : MonoBehaviour, IMoveData
2024-02-03 16:21:32 +01:00
{
[SerializeField] private int playerNumber;
2024-03-01 19:44:22 +01:00
private MoveData moveData = new();
2024-02-03 16:21:32 +01:00
public Gamepad controller { get; private set; }
public bool whipAttack;
2024-02-03 16:58:14 +01:00
public event Action<int> ropeLengthShrinken;
public event Action<int> ropeLengthExtend;
2024-03-01 19:44:22 +01:00
public event Action<MoveData> OnNewMoveData;
2024-02-03 16:21:32 +01:00
2024-02-03 21:35:06 +01:00
public bool useArrowKeys = false;
2024-02-03 16:21:32 +01:00
public int PlayerNum => playerNumber;
2024-02-03 20:01:12 +01:00
private void Start()
2024-02-03 16:21:32 +01:00
{
controller = Gamepad.all.ElementAtOrDefault(playerNumber);
if (controller == null)
{
Debug.LogWarning($"No Gamepad found for player {playerNumber + 1}");
}
}
private void Update()
{
moveData.Movement.x = Input.GetAxisRaw("Horizontal");
moveData.Movement.y = Input.GetAxisRaw("Vertical");
2024-02-27 18:27:37 +01:00
whipAttack = Input.GetKey(KeyCode.R);
2024-02-03 16:21:32 +01:00
2024-02-27 18:27:37 +01:00
if (Input.GetKey(KeyCode.E)) ropeLengthShrinken?.Invoke(playerNumber);
if (Input.GetKey(KeyCode.Q)) ropeLengthExtend?.Invoke(playerNumber);
2024-03-01 19:44:22 +01:00
OnNewMoveData?.Invoke(moveData);
2024-02-03 16:21:32 +01:00
}
}