- Home /
How do to you save time for each player and display it?
Hey guys. Can anyone help me please with this problem I'm having? I want to be able to record the time it takes for each player to complete my game and display it with the times from the other players. Kind of like a leader board. Currently my game will record and store all the times from the previous players as well as the current gamer. The problem exist when I come to display all the times from the people that played my game. As when it does display it overwrites the previous time that was being displayed. Here is my snippet of code:
var SavedTIME2COMPLETEgame;
static var displaySTRING;
function Update () {
if(Input.GetKeyDown("o") && Dist_To_COMPLETELEVEL < 2){
STOPtime = false;
Application.LoadLevel("Completed Level Thirty Seconds");
//SavedTIME2COMPLETEgame(timeRemaining);
SavedTIME2COMPLETEgame = timeRemaining.ToString();
//PlayerPrefs.SetString("", );
//displaySTRING = PlayerPrefs.GetString("", timeRemaining);
print(SavedTIME2COMPLETEgame);
SavedTime(SavedTIME2COMPLETEgame);
//Display_Recorded_Time(SavedTIME2COMPLETEgame);
//DontDestroyOnLoad(GameManager2);
}
}
function SavedTime(SavedTIME2COMPLETEgame : String) {
displaySTRING = PlayerPrefs.GetString("", SavedTIME2COMPLETEgame);
Debug.Log(displaySTRING);
}
The above piece of code is from my main game scene. The following piece is from the complete level/game scene:
function OnGUI () {
GUI.Label(new Rect (10, 10, 100, 100), "Time Recorded: " +GameManager2.displaySTRING);
}
Help much appreciated. Thank you.
Answer by Owen-Reynolds · Apr 05, 2012 at 02:39 PM
You only have a single "print" command --`GUI.Label`, so of course it will only ever display one thing.
If you want to show 4 times, you need four variables and 4 prints. If you know how to use arrays, then have display string be a size 4 array, or else just make displayString2, 3 , 4. Probably easiest to put playerX's score in displayStringX. Then have 4 GUI.Label
s with "if not empty string" in front of each.
Can you give me a example using arrays of how I could display four things using the above example please?
@random if you're willing to finish your game, you're better off finding that kind of example on your own.