57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class PrizeChecker : MonoBehaviour
|
|
{
|
|
[SerializeField] bool needToDisplay = false;
|
|
public TextMeshProUGUI label;
|
|
private void Start()
|
|
{
|
|
|
|
InvokeRepeating("checkPrize", 0, 5);
|
|
StartCoroutine(UpdateLabelVisibility());
|
|
|
|
}
|
|
private void Update()
|
|
{
|
|
|
|
if (needToDisplay)
|
|
{
|
|
Color c = label.color;
|
|
c.a = 0.2f + Mathf.PingPong(Time.time * 0.6f, 0.8f);
|
|
label.color = c;
|
|
}
|
|
}
|
|
void checkPrize()
|
|
{
|
|
bool prizesAvailable = PlayerPrefs.GetInt(KeyVault.PRIZES_AVAILABLE, 0) > 0;
|
|
needToDisplay = !prizesAvailable;
|
|
|
|
if (!SettingsManager.GetBool("DisplayNoPrizes", false))
|
|
{
|
|
needToDisplay = false;
|
|
}
|
|
|
|
}
|
|
IEnumerator UpdateLabelVisibility()
|
|
{
|
|
|
|
while (true)
|
|
{
|
|
float targetAlpha = needToDisplay ? 1 : 0;
|
|
Color currentColor = label.color;
|
|
Color targetColor = currentColor;
|
|
targetColor.a = targetAlpha;
|
|
|
|
while (targetColor != currentColor)
|
|
{
|
|
currentColor = Vector4.MoveTowards(currentColor, targetColor, Time.deltaTime);
|
|
label.color = currentColor;
|
|
yield return null;
|
|
}
|
|
yield return new WaitForSeconds(3);
|
|
}
|
|
}
|
|
}
|