我收到错误:
FormatException:输入字符串的格式不正确 System.UInt64.Parse(System.String s,NumberStyles样式, IFormatProvider提供者)(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()(在Assets / Scripts / TimerScript.cs:19)
以下是代码:
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;
}
}
答案 0 :(得分:1)
尝试:
lastCheastopen = ulong.Parse(PlayerPrefs.GetString(“ LastCheast”,“ 0”));