R
R
realmadness2020-03-29 19:37:39
2D
realmadness, 2020-03-29 19:37:39

How to consider the time of a coroutine relative to the second coroutine?

How to consider the time of a coroutine relative to the second coroutine? That is, the first coroutine was executed, 2 seconds passed and the second coroutine was executed, 2 seconds passed relative to the second - the first one was executed, and so on.

public class activeplatform : MonoBehaviour
{
    public bool on;
    Collider2D coll;
    private void Start()
    {
        StartCoroutine(corout());
        StartCoroutine(corout2());
        coll = GetComponent<Collider2D>();
    }
    IEnumerator corout()
    {
        while (true)
        {
            yield return new WaitForSeconds(2);
            gameObject.GetComponent<Renderer>().material.color = Color.red;
            coll.enabled = false;
        }
    }
    IEnumerator corout2()
    {
        while (true)
        {
            yield return new WaitForSeconds(3);
            {
                gameObject.GetComponent<Renderer>().material.color = Color.blue;
                coll.enabled = true;
            }
        }
    }
}

Here, my coroutines are executed every 2/3 seconds, but my task is to make the second coroutine execute 2 seconds after the first one and vice versa. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-03-29
@DanielMcRon

What .... What kind of nonsense is this, you asked a question an hour ago, maybe we will already think with our heads and teach Unty how to ask questions that are not clear to you, not to us. Answer - Learn Unity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question