101 lines
2.6 KiB
C#
101 lines
2.6 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using TMPro; // add this for TextMeshPro
|
|
|
|
public class BlockDrop_GameManager3D : MonoBehaviour
|
|
{
|
|
public static BlockDrop_GameManager3D Instance { get; private set; }
|
|
|
|
[Header("Core")]
|
|
public float gameTime = 120f;
|
|
public Transform exitTransform;
|
|
public bool exitHiddenAtStart = false;
|
|
|
|
[Header("Difficulty")]
|
|
public BlockDrop_BunnyAI3D bunnyPrefab;
|
|
public Transform bunnyParent;
|
|
public float swarmEverySeconds = 25f;
|
|
public int spawnCountPerSwarm = 2;
|
|
|
|
[Header("UI")]
|
|
public TextMeshProUGUI timerText; // drag your TMP UI Text here
|
|
|
|
//[Header("Berry Ammo")]
|
|
public int CurrentBerryAmmo { get; private set; } = 1;
|
|
|
|
private float timer;
|
|
public GameObject GameOverObj;
|
|
public GameObject GameWon;
|
|
void Awake()
|
|
{
|
|
if (Instance != null) { Destroy(gameObject); return; }
|
|
Instance = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
timer = gameTime;
|
|
if (exitTransform) exitTransform.gameObject.SetActive(!exitHiddenAtStart);
|
|
StartCoroutine(SwarmRoutine());
|
|
|
|
UpdateTimerUI(); // show initial time
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
timer -= Time.deltaTime;
|
|
if (timer <= 0)
|
|
{
|
|
timer = 0;
|
|
GameOver("Time expired!");
|
|
}
|
|
|
|
UpdateTimerUI();
|
|
}
|
|
|
|
private void UpdateTimerUI()
|
|
{
|
|
if (timerText != null)
|
|
{
|
|
int minutes = Mathf.FloorToInt(timer / 60f);
|
|
int seconds = Mathf.FloorToInt(timer % 60f);
|
|
timerText.text = $"{minutes:00}:{seconds:00}";
|
|
}
|
|
}
|
|
|
|
public void RevealExit() { if (exitTransform) exitTransform.gameObject.SetActive(true); }
|
|
|
|
public void SpawnBunny(Vector3 pos)
|
|
{
|
|
if (bunnyPrefab != null)
|
|
{
|
|
Debug.Log("Spawning Bunny");
|
|
Instantiate(bunnyPrefab, new Vector3(pos.x, pos.y, 0f), Quaternion.identity, bunnyParent);
|
|
}
|
|
}
|
|
|
|
IEnumerator SwarmRoutine()
|
|
{
|
|
var wait = new WaitForSeconds(swarmEverySeconds);
|
|
yield return new WaitForSeconds(2);
|
|
while (true)
|
|
{
|
|
for (int i = 0; i < spawnCountPerSwarm; i++)
|
|
{
|
|
SpawnBunny(new Vector3(Random.Range(-7f, 7f), Random.Range(0f, 8f), 0f));
|
|
}
|
|
yield return wait;
|
|
}
|
|
}
|
|
|
|
public void AddBerryAmmo(int amt) { CurrentBerryAmmo += amt; }
|
|
public void ConsumeBerryAmmo(int amt) { CurrentBerryAmmo = Mathf.Max(0, CurrentBerryAmmo - amt); }
|
|
|
|
public void GameOver(string reason)
|
|
{
|
|
Debug.Log("Game Over: " + reason);
|
|
GameOverObj.SetActive(true);
|
|
Time.timeScale = 0f;
|
|
}
|
|
}
|