Hello together!
First of all, i am not a programmer so this code might look a bit funny. Basically what i’m trying to do is a best Time board. I have set up a text UI and attached this C# script to it.
I wish to have a code where the best Time of the Player always overwrites his last worser time. If possible: i would also like to delete the saved time’s with a simple keydown. So that the Player always can restart his time if he wants to.
I am really frustrated because i didn’t find any other documentations on how to do a simple and proper highscore board. So i hope that somebody here could help me :).
I am also open for new or other ideas.
Thank’s for the effort!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class erste : MonoBehaviour {
public float zeit;
public float zwischenzeit= 19.0f; // by default
private string topname;
public Text TotalEins; // UI Text
// Use this for initialization
void Start () {
zeit = PlayerPrefs.GetFloat ("Time"); // get saved Time
zwischenzeit = zeit;
ErstePlatz ();
}
void ErstePlatz () {
for (zwischenzeit = PlayerPrefs.GetFloat("erster"); zwischenzeit > zeit; zwischenzeit--) {
PlayerPrefs.SetFloat ("erster", zwischenzeit);
topname = PlayerPrefs.GetString ("Name").ToString ();
TotalEins.text = "Name: " + topname + " " + "Time: " + zwischenzeit.ToString ();
}
}
}