Advertisement
Guest User

GenerateGrid.cs

a guest
Jan 30th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GenerateGrid : MonoBehaviour {
  6. public float spawnSpeed;
  7. public GameObject block1;
  8. public uint MaxTotalGridSize = 200;
  9. public uint griddistance = 8;
  10. public bool resetgrid1 = false;
  11. public uint GridSize = 0;
  12.  
  13.  
  14. void Start () {
  15. CreateWorld();
  16. }
  17.  
  18. void Update () {
  19.  
  20.  
  21.  
  22. GridSize = MaxTotalGridSize;
  23.  
  24. if (resetgrid1 == true) {
  25. ResetGrid ();
  26. }
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34. // IEnumerator CreateWorld() {
  35.  
  36. // yield return new WaitForSeconds (spawnSpeed);
  37. // for(uint x =0; x<GridSize; x+=griddistance) {
  38. // yield return new WaitForSeconds (spawnSpeed);
  39. // for(uint z =0; z<GridSize; z+=griddistance) {
  40. // yield return new WaitForSeconds (spawnSpeed);
  41. // GameObject block = Instantiate(block1);
  42. // block.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y, this.transform.position.z + z);
  43. // block.transform.parent = this.transform;
  44. // }
  45. // }
  46. // }
  47.  
  48.  
  49.  
  50.  
  51. void CreateWorld() {
  52.  
  53.  
  54. for(uint x =0; x<GridSize; x+=griddistance) {
  55.  
  56. for(uint z =0; z<GridSize; z+=griddistance) {
  57.  
  58. GameObject block = Instantiate(block1);
  59. block.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y, this.transform.position.z + z);
  60. block.transform.parent = this.transform;
  61. }
  62. }
  63. }
  64.  
  65.  
  66.  
  67. public void ResetGrid(){
  68. foreach (Transform child in transform) {
  69. GameObject.Destroy(child.gameObject);
  70. }
  71. // StartCoroutine(CreateWorld());
  72. CreateWorld ();
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement