Hi friends, I’m having trouble using PlayPrefs to save and load lap times. Any advice would be greatly appreciated.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LapTimeManager : MonoBehaviour
{
public static int MinuteCount;
public static int SecondCount;
public static float MilliCount;
public static string MilliDisplay;
public GameObject MinuteBox;
public GameObject SecondBox;
public GameObject MilliBox;
void Update()
{
MilliCount += Time.deltaTime * 10;
MilliDisplay = MilliCount.ToString("F0");
MilliBox.GetComponent<Text>().text = "" + MilliDisplay;
if (MilliCount >= 9)
{
MilliCount = 0;
SecondCount += 1;
}
if (SecondCount <= 9)
{
SecondBox.GetComponent<Text>().text = "0" + SecondCount + ".";
}
else
{
SecondBox.GetComponent<Text>().text = "" + SecondCount + ".";
}
if (SecondCount >= 59)
{
SecondCount = 0;
MinuteCount += 1;
}
if (MinuteCount <= 9)
{
MinuteBox.GetComponent<Text>().text = "0" + MinuteCount + ":";
}
else
{
MinuteBox.GetComponent<Text>().text = "" + MinuteCount + ":";
}
}
}
/// Load Lap Time
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LoadLapTime : MonoBehaviour
{
public int MinCount;
public int SecCount;
public float MilliCount;
public GameObject MinDisplay;
public GameObject SecDisplay;
public GameObject MilliDisplay;
void Start()
{
MinCount = PlayerPrefs.GetInt("MinSave");
SecCount = PlayerPrefs.GetInt("SecSave");
MilliCount = PlayerPrefs.GetFloat("MilliSave");
MinDisplay.GetComponent<Text>().text = "" + MinCount + ":";
SecDisplay.GetComponent<Text>().text = "" + SecCount + ".";
MilliDisplay.GetComponent<Text>().text = "" + MilliCount;
}
}