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

46 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerInput : MonoBehaviour, IMoveData
{
[SerializeField] private int playerNumber;
private MoveData moveData = new();
public Gamepad controller { get; private set; }
public bool whipAttack;
public event Action<int> ropeLengthShrinken;
public event Action<int> ropeLengthExtend;
public event Action<MoveData> OnNewMoveData;
public bool useArrowKeys = false;
public int PlayerNum => playerNumber;
private void Start()
{
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");
whipAttack = Input.GetKey(KeyCode.R);
if (Input.GetKey(KeyCode.E)) ropeLengthShrinken?.Invoke(playerNumber);
if (Input.GetKey(KeyCode.Q)) ropeLengthExtend?.Invoke(playerNumber);
OnNewMoveData?.Invoke(moveData);
}
}