|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using NaughtyAttributes;
- using Variables;
-
- public class JoinManager : MonoBehaviour
- {
- [SerializeField]
- private float m_JoinTime = 10;
-
- [SerializeField]
- private float m_extraWaitTime = -8;
-
- [SerializeField]
- private Reference<float> m_CountDown;
-
- [SerializeField]
- private PlayerManager m_playerManager;
-
- [SerializeField, Scene]
- private string m_nextScene;
-
- [SerializeField, Scene]
- private string m_menuScene;
-
- [SerializeField]
- private PlayerList m_playerList;
-
- // Start is called before the first frame update
- void Start()
- {
- m_playerManager.AllowJoin(true);
- StartCoroutine(DoCountDown(m_JoinTime));
- }
-
- private IEnumerator DoCountDown(float totalTime)
- {
- m_CountDown.Value = totalTime;
-
- while ((m_CountDown > 0 && m_playerList.PlayerCount > 0) || (m_CountDown > -m_extraWaitTime && m_playerList.PlayerCount == 0))
- {
- m_CountDown.Value -= Time.deltaTime;
- yield return new WaitForEndOfFrame();
- }
-
- CountDownFinished();
-
- }
-
- private void CountDownFinished()
- {
- m_playerManager.AllowJoin(false);
-
- if (m_playerList.PlayerCount > 0)
- UnityEngine.SceneManagement.SceneManager.LoadScene(m_nextScene);
- else
- UnityEngine.SceneManagement.SceneManager.LoadScene(m_menuScene);
- }
- }
|