Increment variable based on real time not frames update.

I have recorded my problem in this video:

I would like to increment a variable based on every 5 seconds passed since the start of the game, independent of frame update rate.

Below is my code:

public static var playerDays : int = 0;
function Update ()

 var gameTime = Time.time;

guiText.text = gameTime.ToString();

if(gameTime > 5) {
playerDays ++;

guiText.text = gameTime.ToString()+ " A day in game time";



to do that you could do this inside function update:

var gametime : float = Time.deltaTime;

if(gametime > 5.0){



What you wanna do is compare the passed time to the time you record on your gameTime variable. Say you wanted a day to pass every 5 seconds, you could do this

var secondsPerDay = 5.0f;
private var gameTime = Time.time;

public static var playerDays : int=0;

function Update () {
    if(Time.time > gameTime + secondsPerDay) {
        // Reset your timer
        gameTime = Time.time;

I haven’t tested the code, so let me know if there are any compiling issues or if there is any other issue. Best of luck :slight_smile: