Skip to content

Instantly share code, notes, and snippets.

@QRemark
Created August 31, 2024 10:39
Show Gist options
  • Select an option

  • Save QRemark/2afdd0386daf91fbb85ce7aed70acce9 to your computer and use it in GitHub Desktop.

Select an option

Save QRemark/2afdd0386daf91fbb85ce7aed70acce9 to your computer and use it in GitHub Desktop.
Счетчик
using System.Collections;
using TMPro;
using UnityEngine;
public class ScoreDz : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI _text;
private bool _isRunning = true;
private int _score = 1;
private Coroutine _countdownCoroutine;
private void Start()
{
_text.text = "";
_countdownCoroutine = StartCoroutine(Countdown(0.5f));
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (_isRunning)
{
_isRunning = false;
StopCoroutine(_countdownCoroutine);
}
else
{
_isRunning = true;
_countdownCoroutine = StartCoroutine(Countdown(0.5f));
}
}
}
private IEnumerator Countdown(float delay)
{
var wait = new WaitForSecondsRealtime(delay);
for (int i = _score; i > 0; i++)
{
_score++;
DisplayCountdown(_score);
yield return wait;
}
}
private void DisplayCountdown(int count)
{
_text.text = "Счетчик ДЗ: " + count.ToString("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment