Y
Y
Yuri2020-07-20 16:44:04
C++ / C#
Yuri, 2020-07-20 16:44:04

How to make arrow reload logic with coroutine?

Can you help with writing a reload coroutine? The algorithm is as follows: before shooting, check a boolean variable that will display whether the player is ready to shoot or not. This variable must be changed from the inspector. On a successful shot, a coroutine is launched that counts down the reload time set from the inspector, while changing the value of the boolean variable described above. I have one coroutine (lifetime) written in another script:

private IEnumerator StartLife()
    {
        yield return new WaitForSeconds(lifeTime);
        Destroy(gameObject);
        yield break;
    }

The logic of the second coroutine needs to be written in the player's script, where I carry out the shot. I would be grateful if you could help me write my own coroutine. Or fix this coroutine.
5f15b7a0c4134345867886.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2020-07-20
@Griboks

Reloading is done differently. You remember the time of the shot. When firing again, check
Time.time - lastTime >= cooldown

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question