My coroutine is only firing once for the first rendered red cube. The other ones in my beat map get rendered but do not move. Am i missing something? Thanks in advance!
// Update is called once per frame
void Update()
{
int roundedBeat = (int)Math.Round(music.songPositionInBeats, 0);
if(i < beatmap.myPlayerList.player.Length && roundedBeat == beatmap.myPlayerList.player*.beat){*
//rendering a new cube
// Create a new cube primitive to set the color on
GameObject redCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
// Get the Renderer component from the new cube
var cubeRenderer = redCube.GetComponent();
// Call SetColor using the shader property name “_Color” and setting the color to red
cubeRenderer.material.SetColor(“_Color”, Color.red);
i++;
StartCoroutine(Movement(redCube));
}
}
IEnumerator Movement(GameObject cube){
// to move the game object
redStartPosition = cube.transform.position;
while(elapsedTime < desirecDuration){
elapsedTime += Time.deltaTime;
float percentageComplete = elapsedTime / desirecDuration;
cube.transform.position = Vector2.Lerp(redStartPosition, redEndPosition, percentageComplete);
yield return null;
}
yield return null;
}
}