Files
PIM_7/Assets/_Scripts/ResourceManager.cs
T
2026-06-04 15:09:10 +03:00

61 lines
1.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class ResourceManager : MonoBehaviour
{
public static ResourceManager Instance { get; private set; }
public int playerScore;
public int enemyScore;
public Text pointsText;
public Text enemyPointsText;
public TerritoryUI territoryUI;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
}
private void Start()
{
UpdateScoreUI();
}
public void AddPlayerPoints(int amount)
{
playerScore += Mathf.Max(0, amount);
UpdateScoreUI();
}
public void AddEnemyPoints(int amount)
{
enemyScore += Mathf.Max(0, amount);
UpdateScoreUI();
}
private void UpdateScoreUI()
{
if (pointsText != null)
{
pointsText.text = "Player Points: " + playerScore;
}
if (enemyPointsText != null)
{
enemyPointsText.text = "Enemy Points: " + enemyScore;
}
if (territoryUI != null)
{
territoryUI.SetScore(playerScore, enemyScore);
}
}
}