x


Played time?

Is there a variable that you can set to see how long you'r playing the current scene? I would realy like to make like a guilabel in the left corner of my screen saying how long the player is already playing. Ty!

more ▼

asked Apr 05 '12 at 07:45 AM

starvar gravatar image

starvar
58 12 17 19

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

1 answer: sort voted first

You just need to have a variable that increments itself each second. Here's a very simple script. First go to GameObject>CreateOther>GUIText.

Drag this script into an empty game object and add the GUIText that you created into the timeDisplay variable in the inspector window

var playedTime : float;
var timeDisplay : GUIText;

function Start(){
    playedTime = 0.0;
}    

function Update(){

    playedTime += Time.deltaTime;
    timeDisplay.text = Mathf.RoundToInt(playedTime).ToString();

}

This script should work, tried already. I Hope this helped

-Vatsal

more ▼

answered Apr 05 '12 at 08:25 AM

vatsalAtFEI gravatar image

vatsalAtFEI
734 13 18 25

I would suggest using co-routines for this, in your start() method call a coroutine that yields for 1 second at a time and use Time.timeSinceLevelLoad.

This will have a much lower overhead than running on each update - otherwise I would question your players need to know time to a fraction of a second.

Note: this may break if you are using addative level loading (not tested this - just a hunch)

Apr 05 '12 at 01:53 PM zz74b
(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:

x821
x572
x97
x9

asked: Apr 05 '12 at 07:45 AM

Seen: 425 times

Last Updated: Apr 05 '12 at 01:53 PM