I have a saved counter value that I load at runtime. This value triggers how many GameObjects should be instantiated.
eg. The counter value loaded in = 5, so 5 gameobjects are then instantiated. I then add these GameObjects to a list.
I also have a saved list of 5 names(strings) that is also loaded in at runtime.
I want to assign each of the 5 names to a component located on each of the 5 instantiated gameobjects.
eg. stringName[0] is assigned to a component on Gameobject[0]
stringName[1] is assigned to a component on Gameobject[1]
I understand I can use a bunch lines like example in my case below
gameObjectList[0].GetComponent<DistanceToCheckpoint>().title = nameStringList[0];
gameObjectList[1].GetComponent<DistanceToCheckpoint>().title = nameStringList[1];
gameObjectList[2].GetComponent<DistanceToCheckpoint>().title = nameStringList[2];
However, I understand I need a loop as I won’t know the exact amount of names and GameObjects there will be on the respective lists and will get indexOutofRange exception
I’m just wondering how to create a loop where the index number on the Gameobject list corresponds to the index number on the string list but not sure how to go about it.