public void UpdateHighScores() { TrackStats track = GetOrCreate(GameManager.instance.raceInfo.selectedTrack.sceneName); RaceInfo raceInfo = GameManager.instance.raceInfo; string lastName; float lastValue; if (raceInfo.fastestLap < track.fastestLap.valueInSeconds || track.fastestLap.valueInSeconds == 0) { lastName = track.fastestLap.name; lastValue = track.fastestLap.valueInSeconds; track.fastestLap.valueInSeconds = raceInfo.fastestLap; track.fastestLap.name = "Default"; Debug.Log("NEW FASTEST LAP!"); Debug.Log(string.Format("Last Fastest: {0} -{1}", raceInfo.parseTimeFromSeconds(lastValue), lastName)); } if (raceInfo.totalSeconds < track.fastestTotal.valueInSeconds || track.fastestTotal.valueInSeconds == 0) { lastName = track.fastestTotal.name; lastValue = track.fastestTotal.valueInSeconds; track.fastestTotal.valueInSeconds = raceInfo.totalSeconds; track.fastestTotal.name = "Default"; track.ghost = GameManager.instance.playerGhostData.trackData; Debug.Log("NEW FASTEST TOTAL!"); Debug.Log(string.Format("Last Total: {0} -{1}", raceInfo.parseTimeFromSeconds(lastValue), lastName)); } track.totalPlayTime += raceInfo.totalSeconds; }
public TrackStats GetOrCreate(string track) { int i = keys.IndexOf(track); if (i >= 0) { return(values[i]); } else { keys.Add(track); TrackStats t = new TrackStats(); t.name = track; t.fastestLap = new HighScoreEntry(); t.fastestTotal = new HighScoreEntry(); t.totalPlayTime = 0f; values.Add(t); return(t); } }
public IEnumerator CountDown() { //Sets current state to Start currentState = GameState.RaceStart; //wait 5 seconds before start of race //should have countdown timer here Debug.Log("START YOUR ENGINES!"); yield return(new WaitForSeconds(1f)); Debug.Log("GET READY!"); yield return(new WaitForSeconds(1f)); Debug.Log("3.."); yield return(new WaitForSeconds(1f)); Debug.Log("2.."); yield return(new WaitForSeconds(1f)); Debug.Log("1.."); yield return(new WaitForSeconds(1f)); Debug.Log("GO!"); TrackStats highScore = highScoreAsset.GetOrCreate(raceInfo.selectedTrack.sceneName); if (highScore.ghost != null && highScore.ghost.lap.Count > 0) { playerGhostData.savedTrackData = highScore.ghost; playerGhostData.StartGhostingPlayerLaps(); } CheckLastLap(); //change game state to racing currentState = GameState.Racing; yield return(null); }