PlayerInput.cs (1199B)
1 using Slimecing.Characters; 2 using UnityEngine; 3 using UnityEngine.InputSystem; 4 5 namespace Slimecing.InputSystem 6 { 7 [RequireComponent(typeof(CharacterMovementController))] 8 public class PlayerInput : MonoBehaviour, SlimeControls.IVsGameplayActions 9 { 10 [SerializeField] private SlimeControls playerControls; 11 12 private CharacterMovementController _characterMovementController; 13 14 private void Awake() 15 { 16 playerControls = new SlimeControls(); 17 playerControls.VsGameplay.SetCallbacks(this); 18 _characterMovementController = GetComponent<CharacterMovementController>(); 19 } 20 21 private void OnEnable() 22 { 23 playerControls.Enable(); 24 } 25 26 private void OnDisable() 27 { 28 playerControls.Disable(); 29 } 30 31 public void OnHorizontal(InputAction.CallbackContext context) 32 { 33 _characterMovementController.GetMoveInputH(context.ReadValue<float>()); 34 } 35 36 public void OnVertical(InputAction.CallbackContext context) 37 { 38 _characterMovementController.GetMoveInputV(context.ReadValue<float>()); 39 } 40 } 41 }