Untitled
plain_text
a month ago
2.4 kB
2
Indexable
Never
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; [RequireComponent(typeof(PlayerInput))] public class PlayerInputModule : MonoBehaviour, IPlayerModule { // TODO: Add in charged fire action, and crouch //[SerializeField] private bool _analogMovement; private PlayerInput _playerInput; private InputAction _moveActionValue; private InputAction _sprintActionValue; private InputAction _lookActionValue; private InputAction _jumpActionValue; private InputAction _interactActionValue; private InputAction _fireActionValue; private Vector2 _moveVector; //public bool AnalogMovement { get { return _analogMovement; } } public Vector2 MoveInputVector { get { return _moveActionValue.ReadValue<Vector2>(); } } public Vector2 LookInputVector { get { return _lookActionValue.ReadValue<Vector2>(); } } public bool SprintPressedThisFrame { get { return _sprintActionValue.WasPressedThisFrame(); } } public bool JumpPressedThisFrame { get { return _jumpActionValue.WasPressedThisFrame(); } } public bool InteractPressedThisFrame { get { return _interactActionValue.WasPressedThisFrame(); } } public bool FirePressedThisFrame { get { return _fireActionValue.WasPressedThisFrame(); } } public string CurrentControlScheme { get { return _playerInput.currentControlScheme; } } private void Awake() { Initialize(); Debug.Log(_playerInput.currentActionMap.enabled); } private void Update() { if (Keyboard.current.wKey.wasPressedThisFrame) { Debug.Log("w key pressed"); } } public void Initialize(Player player) { _playerInput = GetComponent<PlayerInput>(); } public void Initialize() { _playerInput = GetComponent<PlayerInput>(); _moveActionValue = _playerInput.actions["Move"]; _sprintActionValue = _playerInput.actions["Sprint"]; _lookActionValue = _playerInput.actions["Look"]; _jumpActionValue = _playerInput.actions["Jump"]; _interactActionValue = _playerInput.actions["Interact"]; _fireActionValue = _playerInput.actions["Fire"]; } public void OnMove(InputValue value) { _moveVector = value.Get<Vector2>(); Debug.Log(_moveVector); } }