Global Game Jam 2021
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.

60 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using NaughtyAttributes;
  5. using Variables;
  6. public class JoinManager : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private float m_JoinTime = 10;
  10. [SerializeField]
  11. private float m_extraWaitTime = -8;
  12. [SerializeField]
  13. private Reference<float> m_CountDown;
  14. [SerializeField]
  15. private PlayerManager m_playerManager;
  16. [SerializeField, Scene]
  17. private string m_nextScene;
  18. [SerializeField, Scene]
  19. private string m_menuScene;
  20. [SerializeField]
  21. private PlayerList m_playerList;
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. m_playerManager.AllowJoin(true);
  26. StartCoroutine(DoCountDown(m_JoinTime));
  27. }
  28. private IEnumerator DoCountDown(float totalTime)
  29. {
  30. m_CountDown.Value = totalTime;
  31. while ((m_CountDown > 0 && m_playerList.PlayerCount > 0) || (m_CountDown > -m_extraWaitTime && m_playerList.PlayerCount == 0))
  32. {
  33. m_CountDown.Value -= Time.deltaTime;
  34. yield return new WaitForEndOfFrame();
  35. }
  36. CountDownFinished();
  37. }
  38. private void CountDownFinished()
  39. {
  40. m_playerManager.AllowJoin(false);
  41. if (m_playerList.PlayerCount > 0)
  42. UnityEngine.SceneManagement.SceneManager.LoadScene(m_nextScene);
  43. else
  44. UnityEngine.SceneManagement.SceneManager.LoadScene(m_menuScene);
  45. }
  46. }