MiniGames/Assets/Scripts/ForageTheGrove/CollectBerryGameManager.cs
2025-07-11 18:05:08 +05:00

67 lines
1.5 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class CollectBerryGameManager : MonoBehaviour
{
[Header("Collectible Settings")]
public GameObject blueberryPrefab;
public int numberOfBerries = 10;
[Header("Spawn Area")]
public Vector2 xBounds = new Vector2(-5f, 5f);
public Vector2 zBounds = new Vector2(-5f, 5f);
public float yHeight = 0.5f;
[Header("UI")]
public TextMeshProUGUI scoreText;
private int collectedCount = 0;
public static CollectBerryGameManager Instance;
private void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
void Start()
{
SpawnBerries();
UpdateScoreUI();
}
public void IncreaseScore()
{
collectedCount++;
UpdateScoreUI();
}
private void UpdateScoreUI()
{
if (scoreText != null)
scoreText.text = "Collected: " + collectedCount;
}
public Vector3 GetRandomPosition()
{
return new Vector3(
Random.Range(xBounds.x, xBounds.y),
yHeight,
Random.Range(zBounds.x, zBounds.y)
);
}
private void SpawnBerries()
{
for (int i = 0; i < numberOfBerries; i++)
{
Vector3 randomPos = new Vector3(
Random.Range(xBounds.x, xBounds.y),
yHeight,
Random.Range(zBounds.x, zBounds.y)
);
Instantiate(blueberryPrefab, randomPos, Quaternion.identity);
}
}
}