You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
995 B
C#
47 lines
995 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public Mole[] moles;
|
|
public float spawnInterval = 1.5f;
|
|
public float gameDuration = 30f;
|
|
public TextMeshProUGUI scoreText;
|
|
public TextMeshProUGUI timerText;
|
|
|
|
private int score = 0;
|
|
private float timeLeft;
|
|
|
|
void Start()
|
|
{
|
|
timeLeft = gameDuration;
|
|
InvokeRepeating(nameof(SpawnMole), 1f, spawnInterval);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
timeLeft -= Time.deltaTime;
|
|
timerText.text = "Time: " + Mathf.CeilToInt(timeLeft);
|
|
|
|
if (timeLeft <= 0f)
|
|
{
|
|
CancelInvoke(nameof(SpawnMole));
|
|
timerText.text = "Time: 0";
|
|
}
|
|
}
|
|
|
|
void SpawnMole()
|
|
{
|
|
if (moles.Length == 0) return;
|
|
|
|
int index = Random.Range(0, moles.Length);
|
|
moles[index].Show();
|
|
}
|
|
|
|
public void AddScore(int points)
|
|
{
|
|
score += points;
|
|
scoreText.text = "Score: " + score;
|
|
}
|
|
}
|