Total time counter (C#)
I would like to add a variable that contains the Total Time spent in game (if possible in Int format). But i want the timer to be counting only for the lifespan of a specific object. And when the player checks his stats,make it so he can see the time in HH:MM format (no seconds).
Thanks in advance!
EDIT: Would a fixed update help me ? If yes,can i change the counter to go up every (N) seconds ?
Answer by CanCo · Oct 22, 2015 at 05:17 AM
Use PlayerPrefs.SetInt() and Time.realtimeSinceStartup.
The time format will have to use your awesome (I know you have them) maths skills to work out the hours and minutes from a number in seconds.
Thank you a lot! Your answer is definitely giving me a way to solve my problem :) but is there any other way other than Time.realtimeSinceStartup? cause i want to be able to manipulate when the timer counts and when it does not ! Also i asked about HH:$$anonymous$$$$anonymous$$ in case i dont need to add a second every second but add a $$anonymous$$ute every $$anonymous$$ute , hence make my game lighter. (dont really know if what am saying is valid though)
Time.time gets the time since the scene was loaded.
You can also set a variable for the time offset. So do
PlayerPrefs.SetFloat("EndTime",Time.realtimeSinceStartUp - offset);
Your answer
![](https://koobas.hobune.stream/wayback/20220612042237im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Have 1 Global Variable With 1 True Value 1 Answer
URP light 2d normalmap gets disabled on runtime 3 Answers
Unity noob here, need help adding footstep logic 1 Answer
In the next scene show the score using player prefab before next level 1 Answer
how to do on single click fire and on drag appears the joystick and get the input from joystick 0 Answers