- Home /
whatever happens, may be quit application or start again, after 10 minutes, I want to do something. I have to run on adroid.
If application Start() work, I want to set after real 10 minutes , but I can quit from application or again start application but time have to be pass real 10 minutes continuously. After 10 minutes, I want to show Text; (ANDROİD)
Answer by OusedGames · Sep 20, 2017 at 03:46 PM
public UnityEngine.UI.Text myText; //Canvas UI text
void Start(){
myText.enabled = false;
}
void Update(){
if(Time.time >= 600f){ //60 seconds times 10
myText.enable = true;
}
}
Thank u for answer but If I start() and quit, time is returning to the beginning, time does not continue.
Answer by JonPQ · Sep 20, 2017 at 04:29 PM
Not quite sure what you are asking.. but several options here...
You can use an ienumerator timer... that waits 10 minutes then runs your code.... but when you switch off device... timer will be gone... So when you switch off... you could store time left in a playerPrefs value, then read it back into timer when you re-load game... You can detect game close with... OnApplicationPause or OnApplicationQuit()
Another Option... You can use System.DateTime to get the current time on your device.... Then add 10 minutes to it.... and save that as a string in playerprefs... and in a variable. as "expiryTime" then everytime you re-open your app, re-read the playerprefs expiry time back into variable... You'll need to Parse the string back into DateTime format
occasionally check if the system.dateTime has expired.... then popup your message at the correct time. (or run whatever code you'd like to run)
void Start()
{
DateTime now = System.DateTime.Now;
now.Add$$anonymous$$inutes(10);
PlayerPrefs.SetString("now", now.ToString());
}
I dont know what can I do. Datetime.now next to future time.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to display a video behind gui on mobile 2 Answers
Access android IR blaster 0 Answers
C# Serialization is working fine in Unity but not on Android 2 Answers