- Home /
Question by
GiacomInox · Sep 17, 2020 at 06:45 AM ·
c#coroutinecoroutines
Can I run multiple instances of the same coroutine in parallel?
If i use StartCoroutine() multiple times for the same coroutine, will multiple indipendent instances of the same coroutine begin to run or will the same instance be reset for each use of the function?
Comment
Best Answer
Answer by Strangertoyourlife · Sep 17, 2020 at 07:07 AM
Yes you can, I have provided an example
public Transform cube;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 3; i++)
{
StartCoroutine(MoveCube());
}
}
IEnumerator MoveCube()
{
yield return new WaitForSeconds(1f);
float cubeY = cube.position.y;
cube.transform.position = new Vector3(cube.position.x, cubeY += 1, cube.transform.position.z);
}
Your answer
Follow this Question
Related Questions
Had difficulties implementing intro to Coroutines from unitypatterns.com. Help? 1 Answer
Can't get while loop to execute more than once in a coroutine before yielding [Solved] 2 Answers
Toggling bools automatically using coroutines 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers