x


Track time between

This is what i have setup so far, 3dtext with a box collider that says begin and another that says finish.

i would like to count the time it too the user to go from begin to end accurately

since Time.time starts as soon as the game begins, i would like to reset it to Zero when the player touches begin, and stop/ print the amount of time it took when they reached finish.

or create another system that can track the time from "begin" to "finish"

explained in another way: create a stop watch timer

more ▼

asked Jul 17 '10 at 03:59 AM

user-3653 (google) gravatar image

user-3653 (google)
86 5 5 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

When the player touches begin do this:

float startTime = Time.time;

to find out how long the actual game/round is running do this:

float curTime = Time.time - startTime;

Done.

more ▼

answered Jul 17 '10 at 05:01 AM

StephanK gravatar image

StephanK
6k 40 53 93

ok for my "begin", i wrote:

float startTime = Time.time; function OnTriggerEnter (other : Collider) { guiText.text = ""+startTime; Destroy(gameObject); }

for the "finish" i wrote:

float curTime = Time.time - startTime; function OnTriggerEnter (other : Collider) { guiText.text = ""+curTime; Destroy(gameObject); }

but it seems there is an error in the finish script and i dont know how to deal with it

Jul 17 '10 at 06:19 AM user-3653 (google)

What happens? Are you destroying the gameObject that contains your guiText? I need to see your code to help you there.

Jul 17 '10 at 10:30 AM StephanK

it tells me a semi colon has to be inserted after the word "float", here is the error......... Timer Begin.js(1,6): UCE0001: ';' expected. Insert a semicolon at the end.......here is line 1......float startTime = Time.time;

Jul 17 '10 at 11:31 PM user-3653 (google)

in javascript the syntac is different. the line should read var startTime : float;

Jul 18 '10 at 12:45 AM StephanK

WONDERFUL! thank you kind sir

Jul 18 '10 at 02:03 AM user-3653 (google)
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x587
x356
x145

asked: Jul 17 '10 at 03:59 AM

Seen: 1518 times

Last Updated: Jul 19 '11 at 01:37 AM