From 1908024332ed4e5a9a313d1a52531eabfaf39e1f Mon Sep 17 00:00:00 2001 From: Pasha Date: Sat, 18 Apr 2026 12:18:20 +0100 Subject: [PATCH] Updated fruit spawner --- Assets/Scenes/GameScene.unity | 3 +-- Assets/Scripts/Game/FruitSpawner.cs | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 25c81d1..2dc27a8 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -2192,7 +2192,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1fc36d0808cf971459d9e430faaeadd9, type: 3} m_Name: m_EditorClassIdentifier: - MaxSpawned: 30 + MaxSpawned: 200 MinSpawnTime: 0 MaxSpawnTime: 0.2 FruitSpawnParent: {fileID: 1944344878} @@ -2213,7 +2213,6 @@ MonoBehaviour: type: 3} BuddhasHandPrefab: {fileID: 4062657912758122058, guid: ebddb1b81a288cc4c993a25bc9efe894, type: 3} - ActiveFruits: [] --- !u!1 &1944344877 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/FruitSpawner.cs b/Assets/Scripts/Game/FruitSpawner.cs index e1b4c7e..3a65702 100644 --- a/Assets/Scripts/Game/FruitSpawner.cs +++ b/Assets/Scripts/Game/FruitSpawner.cs @@ -26,15 +26,14 @@ namespace Fruitomation.Game [SerializeField] private GameObject PitayaPrefab; [SerializeField] private GameObject KiwiPrefab; [SerializeField] private GameObject BuddhasHandPrefab; - - [Header("Read only")] - [SerializeField, InspectorReadOnly] private List ActiveFruits; private float TimeUntilNextSpawn; + private int CurrentItemCount => FruitSpawnParent.childCount; + private void Update() { - if (ActiveFruits.Count <= MaxSpawned && GameStateController.Is(GameState.Simulation)) + if (CurrentItemCount <= MaxSpawned && GameStateController.Is(GameState.Simulation)) { TimeUntilNextSpawn -= Time.deltaTime; @@ -77,10 +76,7 @@ namespace Fruitomation.Game FruitBehaviour behaviour = go.GetComponent(); Debug.Assert(behaviour is not null, "Could not find FruitBehaviour"); - ActiveFruits.Add(behaviour); behaviour.InitBehaviour(GameCanvas); } - - public void RemoveFruit(FruitBehaviour fruit) => ActiveFruits.Remove(fruit); } }