107 lines
2.5 KiB
C#
107 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private PlayerInput controls;
|
|
[SerializeField] private CannonScript[] cannonList;
|
|
[SerializeField] private UIController uiController;
|
|
|
|
[Header("Game Variables")]
|
|
[SerializeField, ReadOnly] private GameState state;
|
|
[SerializeField, ReadOnly] private float points;
|
|
|
|
public static GameManager Instance { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Instance = this;
|
|
state = GameState.InGame;
|
|
points = 0f;
|
|
uiController.UpdatePointsText(points);
|
|
}
|
|
}
|
|
|
|
public void TriggerGameOver(int dimensionID)
|
|
{
|
|
if (state == GameState.Loss) return;
|
|
|
|
// Stop controls
|
|
controls.SwitchCurrentActionMap("UI");
|
|
|
|
// Show Game Over Message
|
|
Debug.Log("Game Over: Dimension " + dimensionID + " has been destroyed");
|
|
|
|
// Show Options (Return to Menu / Retry)
|
|
state = GameState.Loss;
|
|
}
|
|
|
|
public bool OnUpgrade(Upgrade selectedUpgrade)
|
|
{
|
|
if (!(points >= selectedUpgrade.GetCost())) return false;
|
|
points -= selectedUpgrade.GetCost();
|
|
uiController.UpdatePointsText(points);
|
|
return true;
|
|
}
|
|
|
|
public void UpgradeFireRate(FireRateUpgrade upgrade)
|
|
{
|
|
foreach (var cannon in cannonList)
|
|
{
|
|
cannon.SetFireRate(upgrade.GetFireRate());
|
|
}
|
|
}
|
|
|
|
public void UpgradeDamage(DamageUpgrade upgrade)
|
|
{
|
|
foreach (var cannon in cannonList)
|
|
{
|
|
cannon.SetDamage(upgrade.GetDamage());
|
|
}
|
|
|
|
}
|
|
|
|
public void UpgradeBullets(BulletsAmountUpgrade upgrade)
|
|
{
|
|
foreach (var cannon in cannonList)
|
|
{
|
|
cannon.SetBullets(upgrade.GetBullets());
|
|
}
|
|
}
|
|
|
|
public float GetPoints()
|
|
{
|
|
return points;
|
|
}
|
|
|
|
public void SetPoints(float nPoints)
|
|
{
|
|
points = nPoints;
|
|
uiController.UpdatePointsText(points);
|
|
}
|
|
|
|
public void SpendPoints(float amount)
|
|
{
|
|
if (amount > points) return;
|
|
points -= amount;
|
|
uiController.UpdatePointsText(points);
|
|
}
|
|
|
|
public void GainPoints(float amount)
|
|
{
|
|
points += amount;
|
|
uiController.UpdatePointsText(points);
|
|
}
|
|
}
|
|
|
|
public enum GameState
|
|
{
|
|
InGame,
|
|
Loss
|
|
} |