Timer

Hello, i making Timer like Timer in this video http://www.der-softwareentwickler-blog.de/2010/08/09/unity-3d-tutorial-23-zeit-messen/ . But it don’t work. It say:

Here is script

var pastTime : float;
var myWC : Transform;
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();
}

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.

Please could you show me how to do it? I do not know too much in it.

Please how do it?

TobiasS said all, I’ll try to explain also if it can help you but …

myWC.GetGroundHit(hit)

you try to access a function of the myWC object which is a Transform because you wrote:

var myWC : Transform;

and Transform has NO method called “GetGroundHit(hit : WheelHit)” , look at the doc : Unity - Scripting API: Transform

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();
}

Hope it will help you ; )

Thanks!!

It don’t working. Timer work fine, but when i hit object wich tag Finish it does nothing :frowning:

No error, but it don’t working

Here you can download a package with this error. Home - Uploading.com

Please download it and repair