Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

List empties itself

$
0
0
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 efList = new List(); public void Initialize(int damage, int heal, int type, bool a, List 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(); } 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!

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>