Quantcast
Channel: Questions in topic: "tree"
Viewing all articles
Browse latest Browse all 513

Tree spawning problem

$
0
0
i want to make a tree script that spawns new trees around old trees, but i keep having the issue of them spawning in large numbers above the value i have set for them wich is 10, also my trees spawn at 0,0,0, on the map wich is not what i need. how can i spawn them next to an other tree whitin a certain distance ofcourse. any advice would be appreciated. thx public float MaxTreeHeight = 10.0f; //Tree Growth Max Hieght public float TreeGrowthSpeed = 0.1f; //Tree Growth Speed public bool TreeGrowthEnabled = true; //Growing Tree? public bool Spawning = true; //Spawn Tree? public float SpawningTimer = 0.1f; //If Spawn = True, Set Timer To Instantiate Tree public GameObject MyTreeTypePrefab; //Assign Witch Tree Type Should be Spawnd public float MyTreeTypeDistance = 4.0f; //Spawn Tree Distance from main Tree public int i = 0; //Variable for Tree Spawning Distance public int SpawnMaxNumber = 0; //Variable for max number of Tree Spawns void start () { } void Update () //Growing Tree? { if (transform.localScale.x < MaxTreeHeight) //max Tree hieght { TreeGrowthEnabled = true; transform.localScale += new Vector3(0.1f,0.1f,0.1f) * TreeGrowthSpeed * Time.deltaTime; //growth speed } else if (transform.localScale.x > MaxTreeHeight) { TreeGrowthEnabled = false; Spawn (); } } void Spawn () //Spawn Tree? { if (transform.localScale.x > 2 && SpawnMaxNumber < 10) for (i = 0; i < 9; i++) { Spawning = true; Instantiate (MyTreeTypePrefab, new Vector3 (i * 2.0f, 0, 0), Quaternion.identity); SpawnMaxNumber += 1; Debug.Log ("Spawned A Tree" + i); } if (transform.localScale.x < 1) { Spawning = false; } } }

Viewing all articles
Browse latest Browse all 513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>