(I am a beginner) So I was working on a stopwatch to show your current time and a high score to show your high score, but on the way I got this error message saying: Argument 2: cannot convert from 'System.TimeSpan' to 'int'. Can someone help me?
// Start is called before the first frame update
void Start()
{
bestTimeText.text = PlayerPrefs.GetInt("HighScore", 0).ToString(@"mm\:ss\:fff");
currentTime = 0;
stopwatchActive = true;
}
// Update is called once per frame
public void Update()
{
if(bestTime > currentTime)
{
bestTime = currentTime;
}
if(stopwatchActive == true)
{
currentTime = currentTime + Time.deltaTime;
}
TimeSpan time = TimeSpan.FromSeconds(currentTime);
currentTimeText.text = time.ToString(@"mm\:ss\:fff");
PlayerPrefs.SetInt("HighScore", time);
}
public void StartStopwatch()
{
stopwatchActive = true;
}
public void StopStopwatch()
{
stopwatchActive = false;
}
}
↧