Advertisement
Marsh_Mello

TreeGen logicaledits

Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TreeGen : MonoBehaviour
  6. {
  7. public int numberOfTreesPerChunck;//How many trees you want per chunk
  8. public GameObject treePrefab; //Prefab of the tree so we can spawn it
  9.  
  10. public void GenTreeForChunk() //Once the points are all added we need to call this to spawn the trees
  11. {
  12. Vector3[] points = meshData.ReturnVertices();//This returns all of the vertexs
  13.  
  14. for (int i = 0; i < numberOfTreesPerChunck; i++) // This will loop for the amount you want to spawn on that chunk
  15. {
  16.  
  17. GameObject lastTree = Instantiate(treePrefab); //Spawns the prefab
  18.  
  19. lastTree.transform.position = points[Random.Range(0, points.Length)]; //Sets the position of it
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement