infinite trees!!!
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user