From 23482739615e6d4e16594d442a5c9c1dbfadd77d Mon Sep 17 00:00:00 2001 From: Team-on Date: Tue, 4 May 2021 04:02:17 +0300 Subject: [PATCH] Fix popup overlaping --- Ld48/Assets/Scripts/UI/Popup.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Ld48/Assets/Scripts/UI/Popup.cs b/Ld48/Assets/Scripts/UI/Popup.cs index 611269a..4ef2e48 100644 --- a/Ld48/Assets/Scripts/UI/Popup.cs +++ b/Ld48/Assets/Scripts/UI/Popup.cs @@ -9,14 +9,25 @@ using Random = UnityEngine.Random; public class Popup : MonoBehaviour { + static int canvasSortOrder = 100; public bool IsShowed => isShowed; [Header("Refs"), Space] + [SerializeField] Canvas canvas; [SerializeField] CanvasGroup cg; [SerializeField] TextMeshProUGUI textField; bool isShowed; +#if UNITY_EDITOR + private void OnValidate() { + if (!canvas) + canvas = GetComponent(); + if (!cg) + cg = GetComponent(); + } +#endif + private void Awake() { cg.alpha = 0.0f; } @@ -28,6 +39,8 @@ public void SetText(string text) { public void Show() { isShowed = true; + canvas.sortingOrder = canvasSortOrder++; + LeanTween.cancel(gameObject, false); LeanTweenEx.ChangeAlpha(cg, 1.0f, 0.1f).setEase(LeanTweenType.easeInOutQuad); } @@ -35,6 +48,8 @@ public void Show() { public void Hide() { isShowed = false; + --canvasSortOrder; + LeanTween.cancel(gameObject, false); LeanTweenEx.ChangeAlpha(cg, 0.0f, 0.1f).setEase(LeanTweenType.easeInOutQuad); }