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.

61 lines
1.2 KiB

  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]
  14. private Reference<bool> m_noInputAllowed;
  15. [SerializeField,BoxGroup("Settings")]
  16. private float m_speed = 2.0f;
  17. [ShowNonSerializedField]
  18. private Vector2 m_movement;
  19. [ShowNonSerializedField]
  20. private bool m_jump;
  21. public void OnMove(InputAction.CallbackContext context)
  22. {
  23. m_movement = context.ReadValue<Vector2>();
  24. }
  25. public void OnJump(InputAction.CallbackContext context)
  26. {
  27. m_jump = context.ReadValueAsButton();
  28. }
  29. private void Update()
  30. {
  31. if (!m_noInputAllowed)
  32. {
  33. m_characterController.Move(m_movement.x * m_speed, false, m_jump);
  34. m_playerInput.Value = m_movement.magnitude != 0 || m_jump;
  35. }
  36. else
  37. {
  38. m_characterController.Move(0, false, false);
  39. m_playerInput.Value = false ;
  40. }
  41. }
  42. }