| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using TMPro;
- using UnityEngine;
- public class GameManager : MonoBehaviour
- {
- public static GameManager gameManager;
- public TextMeshProUGUI scoreText, timerText;
- public AudioSource gameWon;
- public float timeLeft = 60f;
- public bool gameRunning = true;
- private int currentScore = 0;
- void Awake()
- {
- gameManager = this;
- }
- void Update()
- {
- if (timeLeft > 0)
- {
- timeLeft -= Time.deltaTime;
- timerText.text = "Time: " + Mathf.Round(timeLeft) + "s";
- if(timeLeft<=0) gameWon.Play();
- }
- else
- {
- gameRunning = false;
- timerText.text = "";
- scoreText.text = "Total Score: " + currentScore;
- }
- }
- public void AddPoints()
- {
- currentScore += 100;
- scoreText.text = "Score: " + currentScore;
- }
- }
|