public void CollectData() { if (isWin) { return; } int count = 0; foreach (SusceptibleObject npc in npcPool) { if (npc.status == Status.infected) { count++; } } infectedNpcCount = count; currTime++; if (infectedNpcCount >= totalNpcCount && !isTutorial) { GameManager.instance.WinGame(); isWin = true; } if (collectData) { npcDataNode node = new npcDataNode(currTime, infectedNpcCount); npcData.Add(node); } float percent = (float)infectedNpcCount / (float)totalNpcCount; PopulationBar.instance.UpdatePopulationBar(); }
void Awake() { instance = this; // create lists npcData = new List <npcDataNode>(); npcPool = new List <SusceptibleObject>(); // get each child in transform and add to list foreach (Transform child in transform) { SusceptibleObject so = child.GetComponent <SusceptibleObject>(); if (so != null) { npcPool.Add(so); } } totalNpcCount = npcPool.Count; infectedNpcCount = 0; // collect data at time 0 npcDataNode node = new npcDataNode(currTime, infectedNpcCount); npcData.Add(node); // invoke collect data every 5 mins InvokeRepeating("CollectData", 1f, 1f); //0s delay, repeat every 1s }