public void Reset() { if (playRandomColorCoroutine != null) { StopCoroutine(playRandomColorCoroutine); } foreach (var checkPoint in currentLevel.checkPoints) { checkPoint.ball = ball; checkPoint.raceController = this; checkPoint.gameObject.SetActive(false); } nextCheckPointIndex = 0; nextCheckPoint = currentLevel.checkPoints[0]; nextCheckPoint.gameObject.SetActive(true); nextCheckPoint.ChangeText("START"); color = GetRandomColor(); nextCheckPoint.ChangeColor(color); ball.position = currentLevel.startPosition.position; ball.rotation = currentLevel.startPosition.rotation.eulerAngles.y; terrainController.CleanTerrain(); race.timeElapsed = 0; race.lapTime = 0; race.lapTimes = new List <float>(); race.currentLap = 0; race.isRacing = false; race.isNewRecord = false; onlineController.LoadLeaderBoard(); }
public void OnCheckPoint(CheckPointController checkPoint) { if (nextCheckPoint == checkPoint) { checkPoint.gameObject.SetActive(false); PlaySound(checkPointSound); if (nextCheckPointIndex == 0) { race.currentLap++; if (race.currentLap == 1) // Start { PlaySound(startAudio); race.isRacing = true; race.timeElapsed = 0; if (playRandomColorCoroutine != null) { StopCoroutine(playRandomColorCoroutine); } } else { race.lapTimes.Add(race.lapTime); } if (race.currentLap > race.maxLaps) // End { race.isRacing = false; race.currentLap = 0; CheckLeaderBoard(); playRandomColorCoroutine = StartCoroutine(PlayRandomColor()); return; } if (race.currentLap == race.maxLaps) { Log(race.currentLap == race.maxLaps ? "FINAL LAP !!!" : "LAP #" + race.currentLap); PlaySound(finalLapAudio); } else { Log(race.currentLap == race.maxLaps ? "FINAL LAP !!!" : "LAP #" + race.currentLap); } race.lapTime = 0; } nextCheckPointIndex = (nextCheckPointIndex + 1) % currentLevel.checkPoints.Length; nextCheckPoint = currentLevel.checkPoints[nextCheckPointIndex]; nextCheckPoint.gameObject.SetActive(true); if (nextCheckPointIndex == 0) { if (race.currentLap == race.maxLaps) { nextCheckPoint.ChangeText("FINISH"); } else { nextCheckPoint.ChangeText("LAP " + (race.currentLap + 1)); } } else { nextCheckPoint.ChangeText("LAP " + race.currentLap + "." + nextCheckPointIndex); } hub.color = color; color = GetRandomColor(); nextCheckPoint.ChangeColor(color); } }