using UnityEngine; using UnityEngine.UI; namespace Cryville.Common.Unity { public class Popup : MonoBehaviour { public string Message = ""; LayoutElement layout; float timer = 0; const float DURATION = 5.0f; const float DURIN = 0.4f; const float DUROUT = 0.4f; const float HEIGHT = 50f; #pragma warning disable IDE0051 void Start() { layout = GetComponent(); GetComponentInChildren().text = Message; transform.SetParent(GameObject.Find("PopupList").transform); layout.minHeight = 0; } void Update() { if (timer <= DURIN) layout.minHeight = timer / DURIN * HEIGHT; else if (timer >= DURATION) GameObject.Destroy(gameObject); else if (timer >= DURATION - DUROUT) layout.minHeight = (DURATION - timer) / DUROUT * HEIGHT; timer += Time.deltaTime; } #pragma warning restore IDE0051 } }