Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GenerateGrid : MonoBehaviour {
- public float spawnSpeed;
- public GameObject block1;
- public uint MaxTotalGridSize = 200;
- public uint griddistance = 8;
- public bool resetgrid1 = false;
- public uint GridSize = 0;
- void Start () {
- CreateWorld();
- }
- void Update () {
- GridSize = MaxTotalGridSize;
- if (resetgrid1 == true) {
- ResetGrid ();
- }
- }
- // IEnumerator CreateWorld() {
- // yield return new WaitForSeconds (spawnSpeed);
- // for(uint x =0; x<GridSize; x+=griddistance) {
- // yield return new WaitForSeconds (spawnSpeed);
- // for(uint z =0; z<GridSize; z+=griddistance) {
- // yield return new WaitForSeconds (spawnSpeed);
- // GameObject block = Instantiate(block1);
- // block.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y, this.transform.position.z + z);
- // block.transform.parent = this.transform;
- // }
- // }
- // }
- void CreateWorld() {
- for(uint x =0; x<GridSize; x+=griddistance) {
- for(uint z =0; z<GridSize; z+=griddistance) {
- GameObject block = Instantiate(block1);
- block.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y, this.transform.position.z + z);
- block.transform.parent = this.transform;
- }
- }
- }
- public void ResetGrid(){
- foreach (Transform child in transform) {
- GameObject.Destroy(child.gameObject);
- }
- // StartCoroutine(CreateWorld());
- CreateWorld ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement