Ejemplo n.º 1
0
    private void SetWinnerLogic(int teamIndex)
    {
        if (!hasTeamFinishedRace[teamIndex])
        {
            // Debug.Log("finishhhh");
            hasTeamFinishedRace[teamIndex] = true;
            indicesOfTeamsStillRacing.Remove(teamIndex);
            FinalTeamIndicesOrderedByRank.Add(teamIndex);
            currCheckpoint[teamIndex] = winPoint.transform;

            if (OnTeamWin != null)
            {
                OnTeamWin(teamIndex);
            }

            if (!hasSingleTeamFinishedRace)
            {
                hasSingleTeamFinishedRace = true;
                RaceFinishTime            = raceTime;
                SaveManager.Instance.LevelBeaten(MetaManager.Instance.CurrentLevel, raceTime);
                SaveManager.Instance.UnlockNextLevel();
            }

            if (winningTeam < 0)
            {
                winningTeam = teamIndex;
                if (TeamManager.Instance.TeamsOnThisClient == 2 && TeamManager.Instance.IndicesOfTeamsOnThisClient.Contains(winningTeam))
                {
                    int idxOfWinner = TeamManager.Instance.IndicesOfTeamsOnThisClient.IndexOf(winningTeam);
                    losingTeamOnClient = TeamManager.Instance.IndicesOfTeamsOnThisClient[1 - idxOfWinner];
                    //splitline.gameObject.SetActive(false);
                }
                //isSlowingDown = true;
                //winPoint.GetComponent<BoxCollider>().enabled = false;

                hasWon = true;
            }

            NumberOfTeamsThatHaveFinishedRace++;

            // If not tutorial, finish when second to last place team finishes race
            if (!MetaManager.Instance.isInTutorialLevel && NumberOfTeamsThatHaveFinishedRace >= TeamManager.Instance.TotalNumberOfTeams - 1)
            {
                int idxOfLastTeam = hasTeamFinishedRace.IndexOf(false);
                NumberOfTeamsThatHaveFinishedRace = TeamManager.Instance.TotalNumberOfTeams;
                FinalTeamIndicesOrderedByRank.Add(idxOfLastTeam); // = NumberOfTeamsThatHaveFinishedRace - 1;
            }

            CheckForRaceFinish();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Check whether the race is over or not, and if it is, call the OnRaceFinish() event and show the race finish UI.
    /// </summary>
    private void CheckForRaceFinish()
    {
        if (NumberOfTeamsThatHaveFinishedRace >= TeamManager.Instance.TotalNumberOfTeams)
        {
            if (FinalTeamIndicesOrderedByRank.Count != NumberOfTeamsThatHaveFinishedRace)
            {
                FinalTeamIndicesOrderedByRank.AddRange(indicesOfTeamsThatQuit);
            }

            isRaceOver = true;
            winPoint.GetComponent <BoxCollider>().enabled = false;

            if (OnRaceFinish != null)
            {
                OnRaceFinish();
                OnRaceFinish -= NetworkManager.Instance.OnRaceFinishNetworkCleanUp;
            }
        }
    }