I’m creating a game on Iphone/Android. In my game, user plants a tree then have to wait for that tree grow up. Each time user opens game, I check the time when user planted the tree and the current time, then decide the tree is grew up or not.
The problem is, if user plants the tree, then change device’s time, he/she can cheat to make the tree grow faster.
How to avoid this? Is there a way to get the “real world current time” which user can not change?
The only way to do this (if i’m not wrong) is to query the time from the internet.
You can create a small PHP page that prints the time and host it somewhere on the web, then use WWW to query it whenever you need to find the time.
For e.g.
PHP Page :
<?php
print date("G.i:s", time());
?>
Unity Code
void Start () {
StartCoroutine("getTime");
}
IEnumerator getTime()
{
WWW www = new WWW("http://www.saadkhawaja.com/gettime.php");
yield return www;
Debug.Log("Time on the server is now: " + www.text);
}