Access a variable using string

Lets say I have 20 variables, labelled position1 to position20, and I want to be able to access them in a for loop by referencing them by their number.
I would wish I could use something along the line of:

for (int i = 1; i < list.count; i++){
new Vector3 positionToAnalyse = “position” + “i” //So that the first iteration gives position1 and the next position2

I know this a very stupid way of doing it but I have set up the rest of the code around it so changing it would probably take longer and be more annoying.

Any help is highly appreciated :slight_smile:

accessing them by referencing their number in a loop is a very common thing, that’s pretty much what for and foreach are designed to do… not sure what you are trying to do by bringing strings into it… but you can parse a string into a number, an integer in this case. What you should be doing is putting all your Vector3s into an array or list and iterating through that with foreach. A more detailed explanation of what you are trying to do will result in a more detailed answer.