public static void Write(List <GameObject> Players) { StreamWriter writer = new StreamWriter(path, false); RacerResults RacerInfo = new RacerResults(); for (int i = 0; i < Players.Count; i++) { string Name = Players[i].GetComponent <PlayerInformationScript>().name; string Status = Players[i].GetComponent <PlayerInformationScript>().Status; string Pos = Players[i].GetComponent <PlayerInformationScript>().CurrentPosition; string[] LapTimes = Players[i].GetComponent <PlayerInformationScript>().LapTimes; RaceInformation Info = new RaceInformation(Name, LapTimes, Pos, Status); RacerInfo.RaceInfo[i] = Info; } string json = JsonUtility.ToJson(RacerInfo); writer.Write(json); writer.Close(); }
public void Start() { Path = Application.streamingAssetsPath + "/Resources/Results.json"; string Data = File.ReadAllText(Path); Info = JsonUtility.FromJson <RacerResults>(Data); PlayerName.text = Info.RaceInfo[0].Name; PlayerFinishPos.text = Info.RaceInfo[0].Position; PlayerLap1.text = Info.RaceInfo[0].LapTimes[0]; PlayerLap2.text = Info.RaceInfo[0].LapTimes[1]; PlayerLap3.text = Info.RaceInfo[0].LapTimes[2]; PlayerStatus.text = Info.RaceInfo[0].Status; AIPlayer1Name.text = Info.RaceInfo[1].Name; AIPlayer1FinishPos.text = Info.RaceInfo[1].Position; AIPlayer1Lap1.text = Info.RaceInfo[1].LapTimes[0]; AIPlayer1Lap2.text = Info.RaceInfo[1].LapTimes[1]; AIPlayer1Lap3.text = Info.RaceInfo[1].LapTimes[2]; AIPlayer1Status.text = Info.RaceInfo[1].Status; AIPlayer2Name.text = Info.RaceInfo[2].Name; AIPlayer2FinishPos.text = Info.RaceInfo[2].Position; AIPlayer2Lap1.text = Info.RaceInfo[2].LapTimes[0]; AIPlayer2Lap2.text = Info.RaceInfo[2].LapTimes[1]; AIPlayer2Lap3.text = Info.RaceInfo[2].LapTimes[2]; AIPlayer2Status.text = Info.RaceInfo[2].Status; AIPlayer3Name.text = Info.RaceInfo[3].Name; AIPlayer3FinishPos.text = Info.RaceInfo[3].Position; AIPlayer3Lap1.text = Info.RaceInfo[3].LapTimes[0]; AIPlayer3Lap2.text = Info.RaceInfo[3].LapTimes[1]; AIPlayer3Lap3.text = Info.RaceInfo[3].LapTimes[2]; AIPlayer3Status.text = Info.RaceInfo[3].Status; AIPlayer4Name.text = Info.RaceInfo[4].Name; AIPlayer4FinishPos.text = Info.RaceInfo[4].Position; AIPlayer4Lap1.text = Info.RaceInfo[4].LapTimes[0]; AIPlayer4Lap2.text = Info.RaceInfo[4].LapTimes[1]; AIPlayer4Lap3.text = Info.RaceInfo[4].LapTimes[2]; AIPlayer4Status.text = Info.RaceInfo[4].Status; }