Hey guys I’m Florian (14) and I’m making my first game, it’s a maze game.
I want that you have a timer and if you finish the level, that your best time appears in an other scene (level selection scene). And if your time is not better than your best time, the old best time will stay there.
My version is 5.0.2f1.
Hi Nair, with only the time you need to keep between scenes. It’d be easy enough to just use the PlayerPref class.
Here’s an example of how you can use it:
// Use this to save new times, and do anything else you want to happen at the same time
public void Save(float time)
{
// This checks if you've saved it before
if(PlayerPrefs.HasKey("Timer"))
{
// If you have already saved a time, this gets that time
float currentTimer = PlayerPrefs.GetFloat("Timer");
// Check the current record against the new time
if(currentTimer < time)
{
// New record! .. do anything else you want here :)
// Override the old save with the new time when you beat the record
PlayerPrefs.SetFloat("Timer", time);
}
}
else
{
// This saves it
PlayerPrefs.SetFloat("Timer", time);
}
}
// Use this for when you just want to grab the current time. Will give you back 0 if there's no time yet
public float GetCurrentRecord()
{
if(PlayerPrefs.HasKey("Timer"))
{
return PlayerPrefs.GetFloat("Timer");
}
else
{
return 0;
}
}
What do I need to do that it shows my best time in an other scene (level selection).
I’m sorry that I’m so bad in scripting and everything.
I hope you can tell my step by step what i need to do.
Nigey suggested a solution in the post above by using the user preference.
If that’s too complicated for you. You can used a static variable to store the best time. But it will not be saved permanently, and the score will reset when you quit the game.