In my game, I wanted to change the image by pressing the "S" button. By writing a script, I did it, but by adding new elements, they did not inherit the index of the old images, starting from scratch. I would like to achieve synchronization of the index by elements in my game, so that when I click on the "S" button, all the elements under one index change and have one image, as well as if I add a new image, it receives information about the index of other elements and takes the same image as the other elements "with an inherited index."
NOTE
In my game, five images are determined by the index, starting from 0 and ending with the 4 index.
The new element being created does not inherit the same image as the other elements, but starts the list over from the first image (THIS IS A BIG PROBLEM). Therefore, when all the elements of the column are equal to 1 index, and the new one is 0, by clicking on the "S" button, all the elements of the list except the new one change to 2 index, and the index of the new image becomes 1.
Please help me. I no longer understand how I need to create an index that can be changed when clicked, as well as which is inherited for each image.