- Home /
Best way to store a new variable in each iteration of a for loop?
I have a 'for' loop that is essential for my project to work. I also need it to save to a new variable and affect other game objects depending on which iteration the loop is on. So far I am managing to get it to work using if statements but it is elongating my code to a size that could be drastically reduced. I just want to know what the best way to store new variables in each iteration of a for loop as it would help me out a lot.
Thanks in advance :)
Answer by iveL_newO · May 16, 2020 at 01:36 AM
I don't think I fully understand your question but from what I think it is you could use an array.
float[] floats = new float[numberOfIterations];
for (int i = 0; i < numberOfIterations; i++) {
floats[i] = 0.0f;
}
Your answer
Follow this Question
Related Questions
Changing variable on diffirent gameobject than that the running script is attached to. 1 Answer
How make the same variable have different values for each object ? 1 Answer
toggle gameObjects with a keyPress 1 Answer
Variables on Instantiated Object Cannot Be Changed 1 Answer
OnMouseDown() function is not changing gameobject declared outside. 1 Answer