Files
DropToTheRoots/Game/Assets/Scripts/TreeSpawner.cs
T
2026-06-06 13:37:33 +02:00

24 lines
565 B
C#

using UnityEngine;
public class TreeSpawner : MonoBehaviour
{
public GameObject treePrefab;
public Transform player;
private bool hasSpawned = false;
void Update()
{
if (hasSpawned) return;
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);
}
}
}