Answer the question
In order to leave comments, you need to log in
How to make a unit accrue points every second?
Please help to realize the receipt of bonuses every second. That is, when buying an improvement, it is required that every second score+1. I hope I explained well.
Answer the question
In order to leave comments, you need to log in
The simplest and best option: coroutines
More difficult, but more elegant: create a separate thread
There is such a function as WaitForSeconds, you can call it in an asynchronous function (that is, from a function like async void fun () ).
For example
async void AddBall()
{
while(needAddBall)
{
Ball++;
await new WaitForSeconds(1);
}
}
It will be executed, as it were, in parallel with the main thread of the game, that is, it will not interfere with it.
Without asynchrony, riveted a "sketch"
StartCoroutine(Метод());
void IEnumerator Метод()
{
yield return new WaitForSeconds(1);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question