hello game developers…i have a question that i know that yall expert should know
… how can i make a score system that increases over time?..like for example get 10 points per sec or something like that…thanks for taking the time trying to help!! i really apreciate the fact that ur even reading this!!! thanks!! :razz:
in C# you could probably the timer class an set it interval to 10sec (so each tick is done after 10000ms) and on every tick you increase your score variable. And if you want to end it, you just stop the timer.
hope that helps
Unsure of the reliability with this ( its not well documented ) but this should work
(inside of a script )
void GiveTimeIntervalPoints() { score += 10; } // rewards 10 points
void Start() { InvokeRepeating("GiveTimeIntervalPoints", 0.0f, 1.0f); } // immediately ( 0.0f ) calls GiveTimeIntervalPoints and every second ( 1.0f ) afterwards
and then if you wanted to stop the invoke (its done automatically when the object is destroyed elsewise) you would just call CancleInvoke() and GiveTimeIntervalPoints would not be called every second anymore.
You can use invokerepeating as mentioned. Or use a coroutine and yield for a second each time. Or keep track of time in Update or FixedUpdate. Or calculate something based on (currentTime - startTime) whenever you need it. What’s best depends on the details, but the first two options are probably the most straightforward.
Yea a coroutine would work great. I’d only tap into Update if you already are, not specifying any update functions will give you a performance boost but if your already using them then it could be the way to go.