public void Notify(string receive, Sprite icon) { UI_Notification targetNotif = null; if (activeCount >= totalCount) { targetNotif = FindAvailableNotif(); } if (targetNotif == null) { _Log("No free notification, Creating new one."); targetNotif = (UI_Notification)Instantiate(notifPrefab, this.transform); totalCount = totalCount + 1; } targetNotif.GetComponentInChildren <Text>().text = receive; if (icon == null) { _Log("Got null icon sprite"); } foreach (Transform child in targetNotif.transform) { if (child.gameObject.GetComponent <Image>() != null) { child.gameObject.GetComponent <Image>().sprite = icon; break; } } targetNotif.gameObject.SetActive(true); targetNotif.lifetime = lifetimeInWeeks; activeCount = activeCount + 1; }
public void WeekTicks() { foreach (Transform child in this.transform) { UI_Notification notif = child.gameObject.GetComponent <UI_Notification>(); if (notif.gameObject.activeSelf == false) { continue; } notif.lifetime = notif.lifetime - 1; if (notif.lifetime <= 0) { notif.gameObject.SetActive(false); // Need to use SetActive for the layout to change. (Probably) activeCount = activeCount - 1; } } }