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

50 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerInput : MonoBehaviour, IMoveData
{
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 int PlayerNum = 0;
//private void Start()
//{
// controller = Gamepad.all.ElementAtOrDefault(PlayerNum);
// if (controller == null)
// {
// Debug.LogWarning($"No Gamepad found for player {PlayerNum + 1}");
// }
//}
private void Update()
{
if (PlayerNum == 0)
{
moveData.Movement.x = Input.GetAxisRaw("Horizontal");
moveData.Movement.y = Input.GetAxisRaw("Vertical");
}
else
{
moveData.Movement.x = Input.GetAxisRaw("ArrowHorizontal");
moveData.Movement.y = Input.GetAxisRaw("ArrowVertical");
}
//whipAttack = Input.GetKey(KeyCode.R);
//if (Input.GetKey(KeyCode.E)) ropeLengthShrinken?.Invoke(PlayerNum);
//if (Input.GetKey(KeyCode.Q)) ropeLengthExtend?.Invoke(PlayerNum);
OnNewMoveData?.Invoke(moveData);
}
}