Global Game Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1001 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem;
  5. using Variables;
  6. using NaughtyAttributes;
  7. public class CharacterInputController : MonoBehaviour
  8. {
  9. [SerializeField,Header("References")]
  10. private CharacterController2D m_characterController;
  11. [SerializeField]
  12. private Reference<bool> m_playerInput;
  13. [SerializeField,BoxGroup("Settings")]
  14. private float m_speed = 2.0f;
  15. [ShowNonSerializedField]
  16. private Vector2 m_movement;
  17. [ShowNonSerializedField]
  18. private bool m_jump;
  19. public void OnMove(InputAction.CallbackContext context)
  20. {
  21. m_movement = context.ReadValue<Vector2>();
  22. }
  23. public void OnJump(InputAction.CallbackContext context)
  24. {
  25. m_jump = context.ReadValueAsButton();
  26. }
  27. private void Update()
  28. {
  29. m_characterController.Move(m_movement.x * m_speed,false ,m_jump);
  30. m_playerInput.Value = m_movement.magnitude != 0 || m_jump;
  31. }
  32. }