I am working on a bit of code for a photo grid layout, and I am trying to handle photo reassignment of positions in a for loop after the user deletes a photo. I have tried everything, but I just don’t get it.
This logs the correct previousPositions I want to use:
for (int i = indexToDelete; i < allPhotos.Count; i++)
{
Debug.Log($"allPhotos[{i}], {allPhotos[i].transform.position}");
Debug.Log($"previousPositions[{i}], {previousPositions[i].position}");
}
once I put in the transform changes (of the allPhotos gameobjects), every previousPosition.position changes to previousPosition[indexToDelete]'s position. There is no outside code fiddling with these values, and when I only used the Debug.Log the values were correct. From my understanding, changing the transform values of the allPhotos gameobjects should not affect the transforms values of the previousPositions transforms. What am I overseeing? Thanks!
for (int i = indexToDelete; i < allPhotos.Count; i++)
{
allPhotos[i].transform.position = previousPositions[i].position;
allPhotos[i].transform.rotation = previousPositions[i].rotation;
allPhotos[i].transform.localScale = previousPositions[i].localScale;
Debug.Log($"allPhotos[{i}], {allPhotos[i].transform.position}");
Debug.Log($"previousPositions[{i}], {previousPositions[i].position}");
}