- Home /
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!
Answer by adrenak · Apr 05, 2012 at 08:25 AM
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
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)
Answer by Minidavz · Jan 06, 2016 at 08:57 PM
if im correct:
Time.Time is loaded with the app.
Time.timeSinceLevelLoad is loaded since the level is loaded.
Your answer
Follow this Question
Related Questions
Delaying a dynamic Variable(transform.position for Ex.) 2 Answers
Creating a variable jump using deltaTime in C#. 0 Answers
long loading time android 0 Answers
SyncVar of type long isn't updated on clients 0 Answers
timed value increase? 1 Answer