Added cash counter

This commit is contained in:
2026-03-30 13:44:46 +01:00
parent 59b64a680f
commit 652df5ce01
8 changed files with 1016 additions and 11 deletions

View File

@@ -29,6 +29,14 @@ namespace Fruitomation
private void OnPlayerClicked() => TriggerDestruction();
private void Update()
{
if (!GameStateController.Is(GameState.Simulation))
{
TriggerDestruction();
}
}
private void FixedUpdate()
{
bool contained = IsWithinCanvas(RectTransform, AttachedCanvas.GetComponent<RectTransform>());
@@ -42,6 +50,8 @@ namespace Fruitomation
private void TriggerDestruction()
{
MoneyController.Add((ulong)Random.Range(1, 5));
Spawner.RemoveFruit(this);
Destroy(gameObject);
}

View File

@@ -0,0 +1,43 @@
using UnityEngine.UI;
using UnityEngine;
namespace Fruitomation
{
public class FruitBowlController : MonoBehaviour
{
[Header("UI Elements")]
[SerializeField] private Button UpgradesButton;
[SerializeField] private Button SimulateButton;
[SerializeField] private Button BuildButton;
[SerializeField] private Button PauseButton;
[SerializeField] private Text MoneyText;
private void Awake()
{
UpgradesButton.onClick.AddListener(() =>
{
GameStateController.State = GameState.UpgradeMenu;
});
SimulateButton.onClick.AddListener(() =>
{
GameStateController.State = GameState.Simulation;
});
BuildButton.onClick.AddListener(() =>
{
GameStateController.State = GameState.Building;
});
PauseButton.onClick.AddListener(() =>
{
GameStateController.State = GameState.Paused;
});
}
private void Update()
{
MoneyText.text = $"Current Money: ${MoneyController.Current}";
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b0d01280f650064a9dc9ef817c8930a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +1,5 @@
using PashaBibko.Pacore.Attributes;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
namespace Fruitomation
@@ -24,7 +23,7 @@ namespace Fruitomation
private void Update()
{
if (ActiveFruits.Count <= MaxSpawned)
if (ActiveFruits.Count <= MaxSpawned && GameStateController.Is(GameState.Simulation))
{
TimeUntilNextSpawn -= Time.deltaTime;

View File

@@ -9,32 +9,38 @@ namespace Fruitomation
Building,
UpgradeMenu,
Paused,
None
Default
}
[CreateInstanceOnStart] public class GameStateController : MonoBehaviour
{
private static GameStateController Instance;
private GameState InternalState = GameState.None;
[SerializeField, InspectorReadOnly("Game State")] private GameState InternalState;
public static GameState State
{
get => Instance.InternalState;
set
{
Debug.Log($"Changing state from [{Instance.InternalState}] to [{value}]");
Instance.InternalState = value;
if (Instance.InternalState != value)
{
Debug.Log($"Changing state from [{Instance.InternalState}] to [{value}]");
Instance.InternalState = value;
}
}
}
public static bool Is(GameState state) => State == state;
private void Awake()
{
if (Instance is not null)
{
Debug.LogError($"Cannot have multiple instances of [GameStateController]");
Debug.LogError("Cannot have multiple instances of [GameStateController]");
return;
}
InternalState = GameState.Default;
Instance = this;
}
}

View File

@@ -0,0 +1,31 @@
using PashaBibko.Pacore.Attributes;
using UnityEngine;
namespace Fruitomation
{
[CreateInstanceOnStart] public class MoneyController : MonoBehaviour
{
private static MoneyController Instance;
[SerializeField, InspectorReadOnly("Game State")] private ulong InternalCurrentMoney;
public static ulong Current
{
get => Instance.InternalCurrentMoney;
set => Instance.InternalCurrentMoney = value;
}
public static void Add(ulong amount) => Instance.InternalCurrentMoney += amount;
private void Awake()
{
if (Instance is not null)
{
Debug.LogError("Cannot have multiple instances of [MoneyController]");
return;
}
Instance = this;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6958b34c3d774828a5b36ad962b9fa09
timeCreated: 1774874038