I’m initializing a prefab with a script from another class. The initialize function assigns all the variables values. They all work except for list, list seems to empty itself somewhere in the code.
int Damage, Heal, Type;
bool isSpecial;
private List<int> efList = new List<int>();
public void Initialize(int damage, int heal, int type, bool a, List<int> EList){
Damage = damage;
Heal = heal;
Type = type;
isSpecial = a;
efList = EList;
if(efList.Count > 0){
efList.ForEach( x => print(x) );
}else{
efList.Add(0);
}
}
// Use this for initialization
void Start () {
efList.ForEach( x => print(x) );
print (Damage);
GameObject bManager = GameObject.Find("BattleManager");
bM_SCombat = bManager.GetComponent<BS_Combat>();
}
EDIT TO SHOW WHERE INITIALIZE IS CALLED `IEnumerator createPotion(){
GameObject itemPrefab = (GameObject)Instantiate(Resources.Load("PotionPrefab"), playerGO.transform.position, Quaternion.identity);
itemPrefab.name = "Potion";
ProjectileBehavior itemPrefabScript = itemPrefab.GetComponent<ProjectileBehavior>();
itemPrefabScript.Initialize(Pm_S.pDamage, Pm_S.pHeal, Pm_S.pType, Pm_S.isSpecial, Pm_S.EffectList);
if(Bm_S.ingredNotch > 0){ Bm_S.dumpPotion(); }
itemPrefab.SetActive(false);
anim.Play("ThrowAnim");
yield return new WaitForSeconds(0.25f);
itemPrefab.SetActive(true);
itemPrefab.transform.position = playerGO.transform.position;`
Everything in the Initialize keeps except the list, which prints correctly in the initialize but doesn’t print in the start function (the print that is printing damage works). Is it because I’m using “= new list();”? I’ve tried it without that, and with declaring it in the Initialize but none of that works.
Thanks for the help and sorry ahead of time if I make you feel awful inside for being such a novice!