using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class FastCheckCounters : MonoBehaviour { string PRIZE_BASE = "Счетчик призов "; string STARTS_BASE = "Внесено монет "; string NULLABLE = "(обнуляемый)"; string UNNULLABLE = "(глобальный)"; public TextMeshProUGUI starts, startsNul, prize, prizeNul; public Image timerImage; public float timeToDisable = 3; Coroutine coroutine; private void OnEnable() { RefreshUI(); timeToDisable = 3; coroutine = StartCoroutine(disabling()); } private void OnDisable() { if (coroutine != null) StopCoroutine(coroutine); } private void Update() { bool keepCondition = In.GetButton(ButtonPinMapping.startOnePlayer) && In.GetButton(ButtonPinMapping.startTwoPlayers); if (keepCondition) { timeToDisable = Math.Clamp(timeToDisable + Time.deltaTime * 2, 0, 3); } } void RefreshUI() { starts.text = STARTS_BASE + UNNULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_cash); startsNul.text = STARTS_BASE + NULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_cashNul); prize.text = PRIZE_BASE + UNNULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_prizesgiven); prizeNul.text = PRIZE_BASE + NULLABLE + ": " + PlayerPrefs.GetInt(PrizeSystem.key_prizesgivenNul); } IEnumerator disabling() { while (timeToDisable > 0) { timeToDisable -= Time.deltaTime; timerImage.fillAmount = timeToDisable / 3; yield return null; } gameObject.SetActive(false); } }