Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Hiscores : MonoBehaviour
- {
- Dictionary<int, float> times = new Dictionary<int, float>();
- private void Start()
- {
- for (int level = 1; ; level++)
- {
- string key = "Time" + level;
- if (!PlayerPrefs.HasKey(key))
- break;
- times[level] = PlayerPrefs.GetFloat(key);
- }
- }
- public void StoreTime(int level, float time)
- {
- if (times.ContainsKey(level))
- {
- if (time < times[level])
- {
- times[level] = time;
- }
- PlayerPrefs.SetFloat("Time" + level, time);
- } else
- {
- times[level] = time;
- }
- }
- public string GetTimes()
- {
- string timeString = "Best times:\n\n";
- foreach (KeyValuePair<int, float> kvp in times)
- {
- timeString += "Level" + kvp.Key + ":" + kvp.Value.ToString("#.#") + "\n";
- }
- return timeString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement