- Home /
Give a player gifts if he plays the game every day... how?
Hallo. How can I give a gift to a player, who play the game regurarly, like for each day he plays, he get 1000 monay. How to do that ?;)
Answer by Kleptomaniac · Apr 09, 2012 at 04:51 PM
Use System.DateTime.Now. So for example, just before a game session ends, insert this:
var lastDay : int = System.DateTime.Now.get_Day();
And then, when a player relogs back in, in your Start () function, check whether it's been less than a day since they were last on:
function Start () {
if (System.DateTime.Now.get_Day() - lastDay == 1) {
Debug.Log("Have lotsa money!");
}
}
That should work. :)
Hope that helps, Klep
you said " just before a game session ends, insert this:" which function need to be used? is "onDisable" enough?
Your best bet would be to set lastDay in OnApplicationQuit() in a script with DontDestroyOnLoad, just to be sure.
Also, you'll want to probably save your lastDay integer in your PlayerPrefs and fetch the value at game start, so the value doesn't reset every time the game starts.
Answer by NothAU · Apr 09, 2012 at 09:10 PM
Perhaps a couple of variables, one to track if the player has played today, and another to track the number of days in a row they play.
From there, it's just a matter of getting the system time/date, loading, updating, and saving it on launch, and an if statement to to check if the player has met your criteria, and award the gift.
Your answer
Follow this Question
Related Questions
Placing objects in TD Game 1 Answer
GetComponent Help 1 Answer
Revenue exceeds personal limit 1 Answer
Need help with PlayerPrefs 2 Answers
Making money with Unity 0 Answers