Hi there, this is my first post on here, so sorry if I do not follow a proper format or something.
Essentially, I have two lists of GameObjects. Both lists are the same length. One list is a reference and the other list (let’s call this the normal list) are those same elements but in a different order. What I want to do is to match the positions of each element in the normal list to the position of the same-indexed element in the reference list.
What I have written already works perfectly except for two GameObjects. For some reason in my first and second loop of the for-loop, two positions in my reference list just change for no reason that I can tell.
Here is my code:
private void rotate(List<GameObject> cubeList)
{
//make a copy of cubeList to reference
List<GameObject> referenceList = copyList(cubeList);
//change the cube list
//get temporary values of the first corner and first middle
GameObject tempCorner = cubeList[cubeList.Count - 2];
GameObject tempMiddle = cubeList[cubeList.Count - 1];
//move the corners and middles accordingly in the list
for(int i = cubeList.Count - 1; i > 1; i--)
{
cubeList *= cubeList[i - 2];*
}
//change the first and second cube spots
cubeList[0] = tempCorner;
cubeList[1] = tempMiddle;
//actually move the cubes now by making the cube list position equal to the reference list position
for(int i = 0; i < cubeList.Count; i++)
{
cubeList_.transform.position = referenceList*.transform.position;_
_cubeList.transform.Rotate(new Vector3(0, 0, -90));
}
}
private List copyList(List list)
{*
List copyList = new List();_
for(int i = 0; i < list.Count; i++)
{
copyList.Add(list*);*
}
return copyList;
}
Here are some of my debugger statements, so you can see what I am talking about.
Proper Reference List:
(-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0), (-1.0, -1.0, -1.0), (-1.0, 0.0, -1.0),
Pass 0:
Reference List:
(-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0), (-1.0, 1.0, -1.0), (-1.0, 0.0, -1.0),
Cube List:
(-1.0, 1.0, -1.0), (-1.0, 0.0, -1.0), (-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0),
Pass 1:
Reference List:
(-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0), (-1.0, 1.0, -1.0), (0.0, 1.0, -1.0),
Cube List:
(-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0),
Pass 2:
Reference List:
(1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0), (-1.0, 1.0, -1.0), (0.0, 1.0, -1.0),
Cube List:
(-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0),
Pass 3:
Reference List:
(1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0), (-1.0, 1.0, -1.0), (0.0, 1.0, -1.0),
Cube List:
(-1.0, 1.0, -1.0), (0.0, 1.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, 1.0, -1.0), (1.0, 0.0, -1.0), (1.0, -1.0, -1.0), (0.0, -1.0, -1.0),
and so forth.
Pass 0 and Pass 1 are the only things that don’t work (look at the last two positions, they change on the reference list when they shouldn’t).
I am completely stumped. I have been trying other ways, really all I can think of, but referenceList continues to be altered. It is baffling me. Any help would be appreciatedQ