You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/LevelGroupButton.cs

53 lines
1.4 KiB
C#

2 months ago
using MS;
using TMPro;
2 months ago
using UnityEngine;
using UnityEngine.UI;
using System;
2 months ago
[ExecuteInEditMode]
public class LevelGroupButton : MonoBehaviour
{
public LevelGroup levelGroup;
// Use TMP_Text instead of Text
public TMP_Text TitleLbl;
public TMP_Text LevelCompletdLbl;
public GameObject AwardGoldImage;
public int TotalLevelsCompleted;
private void Start()
{
UpdateUI();
GetComponent<Button>().onClick.AddListener(delegate
{
HomeScene.instance.ShowDetailLevel(this);
HomeScene.instance.PlayButton();
GameObject.FindWithTag("LevelGroupPopup").GetComponent<Popup>().Close();
});
}
private void Update()
{
UpdateUI(); // If more logic is needed, add it here
}
[ContextMenu("UpdateUI")]
public void UpdateUI()
{
base.name = levelGroup.LevelGroupName;
TitleLbl.text = base.name.ToUpper();
LevelCompletdLbl.text = levelGroup.CompletedLevel + " / " + levelGroup.TotalLevel;
// Decide between SetActive or using _2dxFX_GrayScale
if (levelGroup.CompletedLevel >= 5)
{
AwardGoldImage.SetActive(true); // Show award if completed levels >= 5
}
else
{
AwardGoldImage.GetComponent<_2dxFX_GrayScale>().enabled = !(levelGroup.CompletedLevel >= levelGroup.TotalLevel);
}
TotalLevelsCompleted = levelGroup.CompletedLevel;
}
}