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 is assigned to a component on Gameobject
stringName is assigned to a component on Gameobject
I understand I can use a bunch lines like example in my case below
gameObjectList.GetComponent<DistanceToCheckpoint>().title = nameStringList; gameObjectList.GetComponent<DistanceToCheckpoint>().title = nameStringList; gameObjectList.GetComponent<DistanceToCheckpoint>().title = nameStringList;
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.