I receive an error:
FormatException: Input string was not in the correct format System.UInt64.Parse (System.String s, NumberStyles style, IFormatProvider provider) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/UInt64.cs:351) System.UInt64.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/UInt64.cs:99) TimerScript.Awake () (at Assets/Scripts/TimerScript.cs:19)
Below is code:
using System;
using UnityEngine;
using UnityEngine.UI;
public class TimerScript : MonoBehaviour {
public float WaitTime = 7200000.0f;
public Button OpenButton;
public ulong lastCheastopen;
public Text FreeCaseText;
void Awake()
{
lastCheastopen = ulong.Parse(PlayerPrefs.GetString("LastCheast"));
}
private void Start()
{
OpenButton = GetComponent<Button>();
if (!IsCheastReddy())
{
OpenButton.interactable = false;
}
}
private void Update()
{
if (!OpenButton.IsInteractable())
{
PlayerPrefs.SetString("LastCheast", lastCheastopen.ToString());
if (IsCheastReddy())
{
OpenButton.interactable = true;
return;
}
ulong diff = ((ulong)DateTime.Now.Ticks - lastCheastopen);
ulong m = diff / TimeSpan.TicksPerMillisecond;
float secondsLeft = (float)(WaitTime - m) / 1000.0f;
int seconds = ((int)secondsLeft % 60);
int minutes = ((int)secondsLeft / 60) % 60;
int hours = ((int)secondsLeft / 3600) % 24;
string TimerString = string.Format("{0:0}H {1:00}Mim {2:00}Sec", hours, minutes, seconds);
FreeCaseText.text = TimerString;
}
}
public void OkCklickButton()
{
lastCheastopen = (ulong)DateTime.Now.Ticks;
PlayerPrefs.SetString("LastCheast", lastCheastopen.ToString());
PlayerPrefs.Save();
OpenButton.interactable = false;
// lastCheastopen = ulong.Parse(PlayerPrefs.GetString("LastCheast"));
}
private bool IsCheastReddy()
{
ulong diff = ((ulong)DateTime.Now.Ticks - lastCheastopen);
ulong m = diff / TimeSpan.TicksPerMillisecond;
float secondsLeft = (float)(WaitTime - m) / 1000.0f;
if (secondsLeft < 0)
return true;
return false;
}
}