I can’t figure out why only one object changes it’s position while the other doesn’t, I end up with 2 objects on the same position instead of them changing places.
for (int i = 0; i < tilePieceList.Count; i++)
{
GameObject tempG = tilePieceList*;*
tempElement = Random.Range(i, tilePieceList.Count);
tilePieceList*.transform.position = tilePieceList[tempElement].transform.position;*
tilePieceList[tempElement].transform.position = tempG.transform.position;
}
Your tempG is a reference to your tilePeice gameObject. So when you change the transform it’s changed in the tempG object also. Try this:
for (int i = 0; i < tilePieceList.Count; i++) {
Vector3 tempG = new Vector3 (tilePieceList*.transform.position);*
tempElement = Random.Range(i, tilePieceList.Count);
tilePieceList*.transform.position = tilePieceList[tempElement].transform.position;*
tilePieceList[tempElement].transform.position = tempG;
}