Is there a way to detect if an app is run the first time?
I have a setting that is saved as a player pref, the issue is when I install the app for the first time and run it, the value defaults to 0. Is there any way to detect if the app has not been run before? What way I can set the value initially.
int hasPlayed = PlayerPrefs.GetInt( "HasPlayed");
if( hasPlayed == 0 )
{
// First Time
// Initialize...etc
PlayerPrefs.PutInt( "HasPlayed", 1 );
}
else
{
// Not First Time
}
You can also check PlayerPrefs.HasKey for one of the usual prefs, if you’re saving anything else. If it exists, then the game has been played before and the preference saved.
does this check if the game has ever run before, or if this specific .exe file has been executed before?
I need to check wether the player has “reinstalled” the game, better said redoawnloaded.
This code wold check this also but if the user uninstalled the game completely(even deleted the registry like I do) then you have no chance of chasing him
public class LoadSaveManager : MonoBehaviour
{
public int IsFirst;
void Start ()
{
IsFirst = PlayerPrefs.GetInt("IsFirst") ;
if (IsFirst == 0)
{
//Do stuff on the first time
Debug.Log("first run");
PlayerPrefs.SetInt("IsFirst", 1);
} else {
//Do stuff other times
Debug.Log("welcome again!");
}
}
}