- Home /
Is it possible to update variable in Coroutine?
I've got a coroutine that fills a LineRenderer's positions with Vector3s from an array.
The positions are updating every FixedUpdate, but the coroutine passes the same one value into each position of the array. (I'm trying to make these all different)
IEnumerator DrawLine() {
for (int i = 0; i < lineRenderer.positionCount; i++) {
lineRenderer.SetPosition(i, positionChangingEveryFixedUpdate);
}
yield return new WaitForFixedUpdate();
}
Is there a way to get the "positionChangingEveryFixedUpdate" variable to update from FixedUpdate with every loop of the coroutine?
I think you've meant to do yield inside for(){} statement after setting position so you get one position each frame. Right now you fill all positions with same value in single frame. And make for loop infinite with some external variable to disable it; and you don't have to run this script again each frame, otherwise each next iteration will just fill each position with same value.
Teravisor! Thanks man! That fixed it. I didn't realize the position of the yield would affect it like that.
Answer by wyatts · Jul 19, 2017 at 07:48 PM
@Teravisor pointed out that the "yield return new WaitForFixedUpdate();" line needed to be inside of the for loop for it to loop every fixed update.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Why does my array of LineRenders only render one line? 1 Answer
Draw shortest distance between 2 points on a sphere 1 Answer
Line Renderer Issues 1 Answer