Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Commit 2348273

Browse files
committed
Fix popup overlaping
1 parent 964d90d commit 2348273

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Ld48/Assets/Scripts/UI/Popup.cs

+15
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@
99
using Random = UnityEngine.Random;
1010

1111
public class Popup : MonoBehaviour {
12+
static int canvasSortOrder = 100;
1213
public bool IsShowed => isShowed;
1314

1415
[Header("Refs"), Space]
16+
[SerializeField] Canvas canvas;
1517
[SerializeField] CanvasGroup cg;
1618
[SerializeField] TextMeshProUGUI textField;
1719

1820
bool isShowed;
1921

22+
#if UNITY_EDITOR
23+
private void OnValidate() {
24+
if (!canvas)
25+
canvas = GetComponent<Canvas>();
26+
if (!cg)
27+
cg = GetComponent<CanvasGroup>();
28+
}
29+
#endif
30+
2031
private void Awake() {
2132
cg.alpha = 0.0f;
2233
}
@@ -28,13 +39,17 @@ public void SetText(string text) {
2839
public void Show() {
2940
isShowed = true;
3041

42+
canvas.sortingOrder = canvasSortOrder++;
43+
3144
LeanTween.cancel(gameObject, false);
3245
LeanTweenEx.ChangeAlpha(cg, 1.0f, 0.1f).setEase(LeanTweenType.easeInOutQuad);
3346
}
3447

3548
public void Hide() {
3649
isShowed = false;
3750

51+
--canvasSortOrder;
52+
3853
LeanTween.cancel(gameObject, false);
3954
LeanTweenEx.ChangeAlpha(cg, 0.0f, 0.1f).setEase(LeanTweenType.easeInOutQuad);
4055
}

0 commit comments

Comments
 (0)