86 lines
1.6 KiB
C#
86 lines
1.6 KiB
C#
![]() |
using UnityEngine;
|
||
|
using TMPro;
|
||
|
|
||
|
public class ButterflyGameManager : MonoBehaviour
|
||
|
{
|
||
|
public static ButterflyGameManager Instance;
|
||
|
|
||
|
public ButterflyMole Mole;
|
||
|
public ButterflySpawner Spawner;
|
||
|
|
||
|
public TextMeshProUGUI scoreText;
|
||
|
public TextMeshProUGUI timerText;
|
||
|
public GameObject gameOverPanel;
|
||
|
public GameObject winPanel;
|
||
|
|
||
|
public int butterfliesToSpawn = 10;
|
||
|
public float levelTime = 60f;
|
||
|
|
||
|
private float timer;
|
||
|
private int score = 0;
|
||
|
private int butterfliesCaught = 0;
|
||
|
private bool gameEnded = false;
|
||
|
|
||
|
void Awake()
|
||
|
{
|
||
|
Instance = this;
|
||
|
timer = levelTime;
|
||
|
}
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
Spawner.SpawnButterflies(butterfliesToSpawn);
|
||
|
//UpdateUI();
|
||
|
}
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
if (gameEnded) return;
|
||
|
|
||
|
timer -= Time.deltaTime;
|
||
|
timerText.text = "Time: " + Mathf.Ceil(timer).ToString();
|
||
|
|
||
|
if (timer <= 0)
|
||
|
{
|
||
|
EndGame(false); // Time up
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void RegisterCatch()
|
||
|
{
|
||
|
butterfliesCaught++;
|
||
|
AddScore(10);
|
||
|
|
||
|
if (butterfliesCaught >= butterfliesToSpawn)
|
||
|
{
|
||
|
EndGame(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AddScore(int amount)
|
||
|
{
|
||
|
score += amount;
|
||
|
scoreText.text = "Score: " + score;
|
||
|
}
|
||
|
|
||
|
public void EndGame(bool win)
|
||
|
{
|
||
|
gameEnded = true;
|
||
|
if (win)
|
||
|
{
|
||
|
winPanel.SetActive(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
gameOverPanel.SetActive(true);
|
||
|
}
|
||
|
|
||
|
Time.timeScale = 0;
|
||
|
}
|
||
|
|
||
|
public bool IsGameActive()
|
||
|
{
|
||
|
return !gameEnded;
|
||
|
}
|
||
|
}
|