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!
2 Answers
2if im correct:
- Time.Time is loaded with the app.
- Time.timeSinceLevelLoad is loaded
since the level is loaded.
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)
– anon49671812Why not just using Time.time?
– nTu4Ka