In the previous scene I edit some of unit info and save the list.
In the next scene I load in the unit list, generate instances of my units, then copy variables from the loaded list to the prefab's copy. (not sure if this is the best way to do this?)
What I'm seeing is that every Item in the loadList has the same variables that were set on the last item that was added to the load list before saving it. I've confirmed they were all unique before saving and not sure what I'm doing wrong.
Code: Select all
List<Unit> loadList = ES3.Load("playerUnitList", new List<Unit>());
for(int i=0; i < loadList.Count;i++)
{
int unitIdx=UnitDB.GetPrefabIndex(loadList[i]);
startingUnitList.Add(UnitDB.GetItem(unitIdx));
//Debug.Log("loadlist name ["+i+"] of unit " + loadList[i].GetName());
}
for(int i=0; i<startingUnitList.Count; i++){
if(startingUnitList[i]==null) continue;
GameObject unitObj=(GameObject)MonoBehaviour.Instantiate(startingUnitList[i].gameObject, new Vector3(0, 99999, 0), Quaternion.identity);
Unit tempUnit = unitObj.GetComponent<Unit>();
Unit tempUnit2 = loadList[i];[code]
deployingList.Add(tempUnit);
if(loadedFromCache) deployingList[deployingList.Count-1].loadedFromCache=true;
unitObj.transform.parent=UnitManager.GetInstance().transform;
}
[/code]