Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FS_ThirdPerson;
- using System;
- using System.Collections;
- using UnityEngine;
- public class GlideController : SystemBase
- {
- public bool InAction { get; private set; }
- public override SystemState State { get; } = SystemState.Other;
- public bool GlideInputHolding { get; private set; }
- ICharacter player;
- PlayerController playerController;
- CharacterController characterController;
- private void Start()
- {
- player = GetComponent<ICharacter>();
- playerController = GetComponent<PlayerController>();
- characterController = GetComponent<CharacterController>();
- }
- public void Update()
- {
- GlideInputHolding = Input.GetKeyDown(KeyCode.Space);
- }
- public override void HandleFixedUpdate() {
- if (playerController.IsInAir && GlideInputHolding)
- {
- if (!InAction)
- {
- StartCoroutine(StartGliding());
- } else
- {
- StartCoroutine(StopGliding());
- }
- }
- }
- private IEnumerator StartGliding()
- {
- if (InAction) { yield return null; }
- InAction = true;
- Debug.Log("Gliding starts");
- Debug.Log($"Velocity: {characterController.velocity}");
- player.OnStartSystem(this);
- if (playerController.WaitToStartSystem)
- yield return new WaitUntil(() => playerController.WaitToStartSystem == false);
- }
- private IEnumerator StopGliding()
- {
- if (!InAction) { yield return null; }
- InAction = false;
- Debug.Log("Gliding stops");
- player.OnEndSystem(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement