From 48c5da2894128155245e98621a2644b66a3bfeb3 Mon Sep 17 00:00:00 2001 From: cemt1363 Date: Sat, 6 Jun 2026 14:45:55 +0200 Subject: [PATCH] no more infinite trees --- Game/Assets/Scripts/TreeSpawner.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Game/Assets/Scripts/TreeSpawner.cs b/Game/Assets/Scripts/TreeSpawner.cs index c75379f..0bd48a2 100644 --- a/Game/Assets/Scripts/TreeSpawner.cs +++ b/Game/Assets/Scripts/TreeSpawner.cs @@ -9,19 +9,23 @@ public class TreeSpawner : MonoBehaviour void Update() { - - Debug.Log("TreeSpawner running"); - - if (hasSpawned) return; - - if (player.position.y < transform.position.y - 3f) + if (hasSpawned == false) { - hasSpawned = true; + if (player.position.y < transform.position.y - 3f) + { + hasSpawned = true; - float treeHeight = GetComponent().bounds.size.y; - Vector3 spawnPos = (transform.position + Vector3.down * treeHeight) - new Vector3(0,-0.2f,0); + float treeHeight = GetComponent().bounds.size.y; + Vector3 spawnPos = transform.position + Vector3.down * treeHeight + new Vector3(0, 0.2f, 0); - Instantiate(treePrefab, spawnPos, Quaternion.identity); + Instantiate(treePrefab, spawnPos, Quaternion.identity); + } + } + + // Delete trees that are far above the player + if (player.position.y < transform.position.y - 40f) + { + Destroy(gameObject); } } } \ No newline at end of file