Hi guys.
I’m new to Unity and looking for a simple way to convert 30 realtime seconds into 1 DAY of gameplay time and display that on screen as GUI text.
E.g. I have a game where the your character is in prison and I want a counter to tick over from ‘DAY 1’ to ‘DAY 2’ (and so on) every 30 seconds.
Can anyone please suggest a script for that? I’d prefer JS (since it’s what I’m learning), but C# is fine too.
Thanks.
AHardDaysKnight:
Hi guys.
I’m new to Unity and looking for a simple way to convert 30 realtime seconds into 1 DAY of gameplay time and display that on screen as GUI text.
E.g. I have a game where the your character is in prison and I want a counter to tick over from ‘DAY 1’ to ‘DAY 2’ (and so on) every 30 seconds.
Can anyone please suggest a script for that? I’d prefer JS (since it’s what I’m learning), but C# is fine too.
Thanks.
I would do something like this.
var nextDay : float = 30;
var day : int = 1;
function Update () {
if(nextDay > 0) {
nextDay -= Time.deltaTime;
}
else {
nextDay = 30;
day += 1;
}
}
Thanks for the quick response jessee03.
I’ll try this out shortly.
Invokerepeating works nicely in that situation also… especially if you don’t currently have an update function in play
Hi novashot. How would you use that function exactly in the scenario I described? Thanks.
Hey jessee03
That worked great. Thanks.
To make it show up in the game I added this line: guiText.text = “Day” + " " + day;
and attached the script to a GUI Text Game Object.
How would you pause the timer for an event and then have the timer continue once that event has finished?
I want the player to make some decisions at the end of each day. Once that decision has been made the timer continues.
Thanks.
AHardDaysKnight:
Hey jessee03
That worked great. Thanks.
To make it show up in the game I added this line: guiText.text = “Day” + " " + day;
and attached the script to a GUI Text Game Object.
How would you pause the timer for an event and then have the timer continue once that event has finished?
I want the player to make some decisions at the end of each day. Once that decision has been made the timer continues.
Thanks.
You should be able to use Time.timeScale = 0; which will stop time. If that doesn’t work and you just want to stop the timer itself and not the entire game just do this.
var nextDay : float = 30;
var day : int = 1;
var pauseTime : boolean;
function Update () {
if(pauseTime == false) {
if(nextDay > 0) {
nextDay -= Time.deltaTime;
}
else {
nextDay = 30;
day += 1;
}
}
}