Esempio n. 1
0
 void Awake()
 {
     if (_instance == null)
     {
         DontDestroyOnLoad(gameObject);
         _instance = this;
     }
     else if (_instance != this)
     {
         Destroy(gameObject);
     }
 }
Esempio n. 2
0
    private IEnumerator MatchTimer()
    {
        GameEndCondition endCondition = GameDataManager.Data.EndCondition;

        Debug.Log("Match Start");
        MatchDuration = 0;

        Func <bool> TestForDuration = () => MatchDuration > endCondition.MatchDuration;
        Func <bool> TestForScore    = () => players.Aggregate(false, (test, p) => test || p.GetComponent <PlayerBehaviour>().Points >= endCondition.ScoreToWin);
        Func <bool> GameOver        = () => true;

        switch (endCondition.Mode)
        {
        case GameEndConditionMode.score:
            GameOver = TestForScore;
            break;

        case GameEndConditionMode.time:
            GameOver = TestForDuration;
            break;

        case GameEndConditionMode.both:
            GameOver = () => TestForDuration() || TestForScore();
            break;

        default:
            print("WEIRD CASE!!!");
            break;
        }

        while (!GameOver())
        {
            yield return(null);

            MatchDuration += Time.deltaTime;
            GameUIManager.Instance.UpdateTimer((int)MatchDuration);
        }

        GameFinished = true;
        string txt = "";

        foreach (var player in players)
        {
            txt += player.name + " -> " + player.GameUiPosition + " -> " + player.Points;
            Debug.Log(txt);
        }
        GameOverPlayerDataContainer.SetData(players);
        UnityEngine.SceneManagement.SceneManager.LoadScene(GameOverSceneName);
        //endGameCanvas.GetComponentInChildren<TextMeshProUGUI>().text = txt;
    }