Created
August 31, 2024 10:39
-
-
Save QRemark/2afdd0386daf91fbb85ce7aed70acce9 to your computer and use it in GitHub Desktop.
Счетчик
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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