Advertisement
DugganSC

Untitled

Dec 13th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using FS_ThirdPerson;
  2. using System;
  3. using System.Collections;
  4. using UnityEngine;
  5.  
  6. public class GlideController : SystemBase
  7. {
  8. public bool InAction { get; private set; }
  9. public override SystemState State { get; } = SystemState.Other;
  10. public bool GlideInputHolding { get; private set; }
  11.  
  12. ICharacter player;
  13. PlayerController playerController;
  14. CharacterController characterController;
  15.  
  16. private void Start()
  17. {
  18. player = GetComponent<ICharacter>();
  19. playerController = GetComponent<PlayerController>();
  20. characterController = GetComponent<CharacterController>();
  21. }
  22.  
  23. public void Update()
  24. {
  25. GlideInputHolding = Input.GetKeyDown(KeyCode.Space);
  26. }
  27.  
  28. public override void HandleFixedUpdate() {
  29. if (playerController.IsInAir && GlideInputHolding)
  30. {
  31. if (!InAction)
  32. {
  33. StartCoroutine(StartGliding());
  34. } else
  35. {
  36. StartCoroutine(StopGliding());
  37. }
  38. }
  39. }
  40.  
  41. private IEnumerator StartGliding()
  42. {
  43. if (InAction) { yield return null; }
  44. InAction = true;
  45. Debug.Log("Gliding starts");
  46.  
  47. Debug.Log($"Velocity: {characterController.velocity}");
  48.  
  49. player.OnStartSystem(this);
  50. if (playerController.WaitToStartSystem)
  51. yield return new WaitUntil(() => playerController.WaitToStartSystem == false);
  52. }
  53.  
  54. private IEnumerator StopGliding()
  55. {
  56. if (!InAction) { yield return null; }
  57. InAction = false;
  58. Debug.Log("Gliding stops");
  59.  
  60. player.OnEndSystem(this);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement