T
T
Taras Ivanov2020-09-28 20:12:37
Unity
Taras Ivanov, 2020-09-28 20:12:37

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

4 answer(s)
N
Nikolay Alekseev, 2020-09-28
@VariusRain

The simplest and best option: coroutines
More difficult, but more elegant: create a separate thread

A
Alexander Shabanov, 2020-09-28
@SherAlex

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.

H
Hixac, 2020-09-28
@Hixac

Without asynchrony, riveted a "sketch"

StartCoroutine(Метод());

void IEnumerator Метод()
{
    yield return new WaitForSeconds(1);
}

G
Griboks, 2020-09-28
@Griboks

If the game is realtime, then check in FixedUpdate, if it's a milker, then simply by the formula.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question