Time variables not interacting

Hi. I have a script and it has a control to keep the entire level from exploding. Yes, it literally explodes. It is basically this:

public static var time : float;
public static var timeLess : float;

function Start () {
    time = 0;
}

function Update () {
    time = Time.time - timeLess;
    
    if(timeLess < time){
        timeLess = time;
    }
}

But the thing is time does not reset, and it needs to be public and static so that other objects can reference it. Thanks in advance.

You set time to 0 in Start, but you completely overwrite that information in every Update cycle.

You can either keep a “base” time:

function Start() {
    baseTime = Time.time;
}

function Update() {
    time = Time.time - baseTime;
}

Or use timeSinceLevelLoad:

function Update() {
    time = Time.timeSinceLevelLoad;
}

Or increment by deltaTime once per frame:

function Start() {
    time = 0;
}

function Update() {
    time += Time.deltaTime;
}