The problem is not the timer but the code that’s in Update.
Reading the log output tells you where it’s caused: Timer.Update () (at Assets/Timer.js:8) and the problem: MissingMethodException: Method not found: ‘UnityEngine.Transform.GetGroundHit’.
It means: The type Transform doesn’t have a GetGroundHit method. That’s logical of course. Look up the doc for Transform, if needed.
Why this happens?
You define myWC as Transform. But Transform doesn’t have the implementation of your function GetGroundHit()!
Solutions:
Change the type of myWC to whatever class contains GetGroundHit().
Or use the Transform to find an attached script component and call GetGroundHit() on that component.
Or send a message to the object you want to update. Component.SendMessage.
what you probably wanted to write was not Transform, but the type of the object for which you have wrote (or not) this function “GetGroundHit”.
From what I can guess, your variable called myWC probably means “my wheel collider”, so I’d guess that it’s a WheelCollider and not a Transform ! Cause WheelCollider do have a function GetGroundHit() !
Shorter version, try that :
var pastTime : float;
var myWC : WheelCollider;
var guiTime : GUIText;
private var isFinished : boolean = false;
function Update () {
var hit : WheelHit;
if (myWC.GetGroundHit(hit)){
if (hit.collider.gameObject.tag == "Finish"){
isFinished = true;
}
}
if(!isFinished){
pastTime += Time.deltaTime;
}
guiTime.text = pastTime.ToString();
}