- Home /
Question by
CraftingStudio12 · Mar 24, 2018 at 01:59 AM ·
c#unity 5ui
Getting number of seconds a user has been in game
I can't get the text ui to display the number of seconds the user has been in the game
public Text time;
private int value = 0;
void Start () {
textloop();
}
// Update is called once per frame
void Update () {
}
public IEnumerator textloop()
{
while (true)
{
yield return new WaitForSeconds(1);
time.text = "Time: " + value.ToString();
value++;
}
}
}
Comment
Answer by mani3307 · Mar 24, 2018 at 09:51 AM
@CraftingStudio12 I don't know what is wrong with your script but you can use Time class for this, Specifically in your case
Answer by fafase · Mar 24, 2018 at 10:20 AM
Use DateTime instead.
When he enters, grads the current time and then you can just compare:
public class EntryClass:MonoBehaviour
{
private DateTime entryTime;
void Awake()
{
this.entryTime = DateTime.Now;
}
public double GetTimeInGameSeconds()
{
return (Date.Now - this.entryTime).TotalSeconds;
}
}
Your answer
Follow this Question
Related Questions
Changing Button sprite using OnGui method 0 Answers
How do you access the Blocking Mask of GraphicsRaycaster in code? 2 Answers
Resource Counting 1 Answer
How to set a default value for Drop-downs, but not display that value in the actual list? 0 Answers
how to track UI buttons on Image targets 0 Answers