Hi Guys,
I’m having a problem with my list and what happen is that when I change a single value on the list, all the values int the list changes.
Down Below is my code to setup my list.
void PreLoadBattleData()
{
//Preparing the needed List
List<int> tempList = new List<int>(2);
// 0 - 111 SquareNumber
for (int i = 0; i < 112; i++)
{
tempList.Add(0); //Add 0 for occupant
tempList.Add(mapData*); //Add terrain data*
battleData.Add(tempList); //Then integrate it to BattleData
}
}
Then after running some functions I will arrive with this method.
void DeployUnit()
{
int unitSelected = battleManager.GetComponent().popUpPage;
battleManager.GetComponent().battleData[int.Parse(gameObject.transform.parent.name)][0] = (unitSelected + 1);
}
The last line should only change a single value in the list.
In example battleData[50][0] the value from 0 will be changed to 1 but when I print them on the console.
All battleData[(from 0-111)][0] will print the value of 1 even though I only changed 1 part of it.
Please help, this seems basic but I could not find out where did I go wrong.
I’ve tried debugging all the codes that will leave up to that method but only that method can change the values in my List.