Hello, I am using the code below in order to query the correct time on a server. Its a 24 hour timer that never stops. It is working perfectly and I am displaying the correct time on Unity editor with no errors. Except, the problem is I need this timer to run a specific code at exactly 24.00:00 every single day - I mean it works, except you have to be on the app running the scene in order for it to work, which makes sense. How do I get it to run the code at 24.00:00 even if the app is off?
For Example - Lets say you press a button at 21.00:00 and the button disappears. And the only way for the button to reappear is if the timer passes 24:00:00. With the code below you would have to be on the app on the scene at exactly 24.00:00 to turn the button back on. How do I get the button to reappear, when it passes 24.00:00 even if the app was off. So if they get on at 2.00:00 the button is back on and if they press the button again it disappears and they have to wait until the timer hits 24.00:00 for the button to turn back on again but they don’t have to have the app open.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
public Text myText;
string url = "http://www.website.com/gettime.php";
void Update () {
WWW www = new WWW(url);
StartCoroutine(WaitForRequest(www));
}
IEnumerator WaitForRequest(WWW www)
{
yield return www;
// check for errors
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.data);
myText.text = www.data;
if (www.data == "24.00:00") {
Debug.Log("CODE I NEED TO RUN");
}
} else {
Debug.Log("WWW Error: "+ www.error);
}
}
}