How can I store lap times in leaderboards for iOS and Android using Unity

240 views Asked by At

I am trying to save my lap times to the iOS leaderboards and Android leaderboards from unity. For some reason I can't get it in the right format for the lap times to show correctly on the leaderboards.

Does anyone know how they need to be formatted before submitting to the leaderboards for both platforms?

I need them to display in this format: 00:00:00:000

Thanks, Liam

EDIT:

Code Image

Once a new lap time is recorded, I take the total seconds elapsed and push them to the leaderboards. But it does not save as the actual time, it displays as 4 days, 21 hours etc.

1

There are 1 answers

0
NastyDiaper On

I think the best your gonna get is milliseconds. Not sure if your displaying nanoseconds. But here's a snippet.

string FormatTime (float time){
    int intTime = (int)time;
    int minutes = intTime / 60;
    int seconds = intTime % 60;
    float fraction = time * 1000;
    fraction = (fraction % 1000);
    string timeText = String.Format ("{0:00}:{1:00}:{2:000}", minutes, seconds, fraction);
    return timeText;
 }

I won't take credit, it was pulled from Unity Answers. Just Google. Then just store off the float in your PlayerPrefs. I think this is what you're asking for.