Unity: How to track number of days in game

void Awake() {
        if (!GameSettings.hasLaunched)
        {
            GameSettings.hasLaunched = true;
            if (PlayerPrefs.GetString("last_launch", "") == "")
            {
                // first launch
                PlayerPrefs.SetString("last_launch", DateTime.Today.ToShortDateString());
                PlayerPrefs.SetInt("number_of_launch", 1);
            }
            else
            {
                if (PlayerPrefs.GetString("last_launch", "") != DateTime.Today.ToShortDateString())
                {
                    GameSettings.newDay = true;
                    PlayerPrefs.SetInt("number_of_launch", PlayerPrefs.GetInt("number_of_launch") + 1);
                }
                PlayerPrefs.SetString("last_launch", DateTime.Today.ToShortDateString());
            }
            PlayerPrefs.Save();
        }
}
if (GameSettings.newDay && PlayerPrefs.GetInt("number_of_launch") > 3)
{
	GameSettings.newDay = false;
	GameSettings.coins += 10;
	PlayerPrefs.SetInt("coins", GameSettings.coins);
	PlayerPrefs.Save();
	Snowman.instance.message("+ 10 coin");
}

Leave a Reply

Your email address will not be published. Required fields are marked *