I’m trying to add a series of game objects to my list, but when I add them only one prefab is added to list the number of times I want.
When I debug it, it shows the names of all the prefabs I wanted but doesn’t add them to the list.
//the list of game pieces
public List<pieceList> piecesList = new List<pieceList>();
void Start()
{
//for the components/vaibles in my custom class
pieceList pieceInfo = new pieceList();
//this instantiates the game pieces
for (int i = 0; i < 2; i++)
{
pieceInfo.gPiece = (GameObject)Instantiate(Resources.Load("gamePiece" + i), this.transform);
pieceInfo.currPos = 0;
pieceInfo.newPos = 0;
piecesList.Add(pieceInfo);
print(pieceInfo.gPiece);
}
}
it shows “gamePiece1” but I want it to have gamePiece0 and gamePiece1.