Files
DropToTheRoots/Game/Assets/Scripts/TreeSpawner.cs
T
cemt1363 cbfc6e580b added tree fab
as well as the scripts, spawntrigger, spawnpoint and tree cloning
2026-06-06 12:21:16 +02:00

25 lines
611 B
C#

using UnityEngine;
public class TreeSpawner : MonoBehaviour
{
public GameObject treePrefab;
public Transform spawnPoint;
private bool hasSpawned = false;
private static float nextAllowedSpawnTime = 0f;
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
if (hasSpawned) return;
if (Time.time < nextAllowedSpawnTime) return;
hasSpawned = true;
nextAllowedSpawnTime = Time.time + 1f;
Instantiate(treePrefab, spawnPoint.position, Quaternion.identity);
gameObject.SetActive(false);
}
}