Relaible real time?

I am a little confuse about this matter:

Wich of all time function trully represents 1 second allways?

i been using fixedDeltaTime or detlaTime but it runs different on every computer. I need to have a real 1 second reference.

I don’t understand the question? Do you really want to know what the value of 1 second is?

Do you want to do something every one second? Lookup InvokeRepeating in the scripting reference.

Something else?

no. i don’t need to invoke a function. I need a relaiable value of 1 second for a lap timer.

the system is updated either on fixed rate (fixedUpdate) or on frames per second.
neither will give you exactly 1 second in 99.9999% of the cases

but deltaTime etc themself are reliable so the information you get reflect the data that hold for their purpose. deltatime for example the time since the last frame

So what you actually want is a lap time.

using UnityEngine;
using System.Collections;

public class YourScript : MonoBehaviour {

	private float lapStartTime = 0.0f;

    public void startLap()
    {
        lapStartTime = Time.timeSinceLevelLoad;
    }

    // Returns the current time in seconds spent on this lap
    public float timeOnLap()
    {
        return Time.timeSinceLevelLoad - roundStartTime;
    }
}

capture the current time in a variable when the clock activates, and then substract it to the current time… that will give you the passing time… and stop substracting when the object crosses some kind of goal point using a trigger maybe

use Time.time to capture the time

like

startTime = Time.time;

and then

lapTime = Time.time - StartTime;

and then stop doing it when lap is over, and the frozen number is the laptime

hope this helps

Doh!.. i had it running under Update function :sweat_smile:

i know that there’s probably a better way to do it but this is my cronometer:

var LapComplete : boolean;
var LapTimerMinutes : int = 00;
var LapTimerSeconds : int = 00;
var LapTimerMillisec : int = 00;


var LastLapTimeMinutes : int = 00;
var LastLapTimeSeconds : int = 00;
var LastLapTimeMillisec : int = 00;

private var i : int;


function FixedUpdate () {

MinSecMil ();

if (LapTrigger.RunTimer) {LapTimerMillisec += 1000 * Time.fixedDeltaTime ; i = 0;}

if (!LapTrigger.RunTimer){ 
	
	HoldLast ();
	LapComplete = true;
	i ++;			
}

if (LapComplete){
	LapTimerMillisec = 0;
	LapTimerSeconds = 0;
	LapTimerMinutes = 0;
	LapComplete = false;
	}
}

function MinSecMil (){

if (LapTimerMillisec >= 1000){ LapTimerMillisec = 0; LapTimerSeconds++; }
if (LapTimerSeconds >= 60){ LapTimerSeconds= 0; LapTimerMinutes++; }


}

function HoldLast (){
if  (i<1){
	LastLapTimeMillisec = LapTimerMillisec;
	LastLapTimeSeconds = LapTimerSeconds;
	LastLapTimeMinutes = LapTimerMinutes;
}

}
function OnGUI () {


GUI.Box (Rect (Screen.width - 200, 20, 200, 50), "LapTime: " +LapTimerMinutes + ":" +LapTimerSeconds + ":" +LapTimerMillisec + "\nLast Lap: " +LastLapTimeMinutes +":" +LastLapTimeSeconds + ":" +LastLapTimeMillisec);



}

aparently so far runs very close to real time.

oh an this is the starter trigger:

static var RunTimer : boolean;

function Start () {

RunTimer = false;

}


function OnTriggerEnter (other : Collider){

if (other.CompareTag ("LocalPlayer")){
	RunTimer = false;
	Debug.Log ("Timer Stop");
}

}
function OnTriggerExit (other : Collider) {

if (other.CompareTag ("LocalPlayer")){
	RunTimer = true;
		Debug.Log ("Timer Start");
	}
}