infinite trees!!!

This commit is contained in:
cemt1363
2026-06-06 13:37:33 +02:00
parent 508ca14197
commit 99b0071794
3 changed files with 38 additions and 132 deletions
+14 -4
View File
@@ -3,12 +3,22 @@ using UnityEngine;
public class TreeSpawner : MonoBehaviour
{
public GameObject treePrefab;
public Transform spawnPoint;
public Transform player;
private void OnTriggerEnter2D(Collider2D other)
private bool hasSpawned = false;
void Update()
{
if (!other.CompareTag("Player")) return;
if (hasSpawned) return;
Instantiate(treePrefab, spawnPoint.position, Quaternion.identity);
if (player.position.y < transform.position.y - 3f)
{
hasSpawned = true;
float treeHeight = GetComponent<SpriteRenderer>().bounds.size.y;
Vector3 spawnPos = transform.position + Vector3.down * treeHeight;
Instantiate(treePrefab, spawnPos, Quaternion.identity);
}
}
}