treeSpawnCounter
This commit is contained in:
@@ -2,24 +2,21 @@ using UnityEngine;
|
||||
|
||||
public class PatternSelecter : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
bool isStarting = true;
|
||||
void Start()
|
||||
{
|
||||
|
||||
if (isStarting)
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
transform.GetChild(0).gameObject.SetActive(true);
|
||||
} else
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
child.gameObject.SetActive(false);
|
||||
|
||||
int randomIndex = Random.Range(1, transform.childCount);
|
||||
|
||||
transform.GetChild(randomIndex).gameObject.SetActive(true);
|
||||
child.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (TreeSpawner.treeCount == 0)
|
||||
{
|
||||
transform.GetChild(0).gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
int randomIndex = Random.Range(1, transform.childCount);
|
||||
transform.GetChild(randomIndex).gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@ public class TreeSpawner : MonoBehaviour
|
||||
|
||||
private bool hasSpawned = false;
|
||||
|
||||
public static int treeCount;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (hasSpawned == false)
|
||||
@@ -18,7 +21,9 @@ public class TreeSpawner : MonoBehaviour
|
||||
float treeHeight = GetComponent<SpriteRenderer>().bounds.size.y;
|
||||
Vector3 spawnPos = transform.position + Vector3.down * treeHeight + new Vector3(0, 0.2f, 0);
|
||||
|
||||
treeCount++;
|
||||
Instantiate(treePrefab, spawnPos, Quaternion.identity);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user