I am making a fastest time scoreboard system. I just need to work out how you add the 3 floats together. E.g. minutes = 1, seconds = 32 and milliseconds = 382 it would then give a big number of 132382.
Below is my code I made so far but I have an error of cannot implicitly convert float to float.
void Update()
{
if (tutorialTimerOn && !story.StoryActive) //When the game has started and after the story has finished
{
TutorialTimeCalculation();
}
else if (tutorialTimerOn == false && !story.StoryActive && !pauseMenu.activeInHierarchy)
{
newTime = (minutes, seconds, milliseconds);
Debug.Log(newTime);
currentFastestTime = PlayerPrefs.GetFloat("tutorialFastestTime");
if (newTime < currentFastestTime)
{
// New high score!
currentFastestTime = newTime;
PlayerPrefs.SetFloat("tutorialFastestTime", currentFastestTime);
PlayerPrefs.SetString("tutorialFastestTimeText", timerText.text);
}
else
{
// High score hasn't changed
}
}
}
The part of the code where I wrote: newTime = (minutes, seconds, milliseconds); is where I am trying to add these numbers together.
My first thought would be to parse your floats out into strings, then pull out the decimal points, and the append them together, then cast into an int or float or whatever you needed.
Edit - I should say that I’m not very familiar with C#, and there are probably much faster and better ways to do this.
that should work, or even saving as 3 separate values…
or could convert everything into milliseconds, so you can save it as a single value.
(and then can also convert back to min - sec - ms on load)
If you want the specific format you described, then change the 60.0 to 100.0
Really though, you should be storing the time as one value and only converting it into minutes, seconds etc for display rather than the other way around.
I’d like to firstly say thank you to all of you who took some time out of your day to help me with my problem. I am pleased to inform you have now got the fastest time system working, I’d like to give a special thanks to DominoM as that line of code you supplied has sorted out my problem. Nevertheless, a huge thank you to everyone for their input as it gives me a better idea of what to try in the future as I could make things more efficient!
I set Time.timeScale to 0.0f going into the pause menu, and revert it to 1.0f on continuing game. If I needed something more complicated I’d probably accumulate an ignoreTime (during cut scenes etc) to subtract from the endTime.