no more infinite trees
This commit is contained in:
@@ -9,19 +9,23 @@ public class TreeSpawner : MonoBehaviour
|
|||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
if (hasSpawned == false)
|
||||||
Debug.Log("TreeSpawner running");
|
{
|
||||||
|
|
||||||
if (hasSpawned) return;
|
|
||||||
|
|
||||||
if (player.position.y < transform.position.y - 3f)
|
if (player.position.y < transform.position.y - 3f)
|
||||||
{
|
{
|
||||||
hasSpawned = true;
|
hasSpawned = true;
|
||||||
|
|
||||||
float treeHeight = GetComponent<SpriteRenderer>().bounds.size.y;
|
float treeHeight = GetComponent<SpriteRenderer>().bounds.size.y;
|
||||||
Vector3 spawnPos = (transform.position + Vector3.down * treeHeight) - new Vector3(0,-0.2f,0);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user