Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MapGenerator : MonoBehaviour {
  6.  
  7. public Transform cellPerf;
  8. public Vector2 mapSize;
  9.  
  10. [Range(0,1)]
  11. public float border;
  12.  
  13. void Start () {
  14. GeneratorMap ();
  15. }
  16.  
  17.  
  18. void Update () {
  19.  
  20. }
  21.  
  22. public void GeneratorMap()
  23. {
  24. string holderName = "GeneratedMap";
  25. if (transform.FindChild (holderName))
  26. {
  27. DestroyImmediate (transform.FindChild (holderName).gameObject);
  28. }
  29.  
  30. Transform mapHolder = new GameObject (holderName).transform;
  31. mapHolder.parent = transform;
  32.  
  33. for(int x = 0; x< mapSize.x; x++)
  34. {
  35. for(int y = 0; y< mapSize.y; y++)
  36. {
  37. Vector3 cellPosition = new Vector3(-mapSize.x/2 + 0.5f + x, 0, -mapSize.y/2 + 0.5f +y);
  38. Transform newCell = Instantiate(cellPerf, cellPosition, Quaternion.Euler(Vector3.right*90)) as Transform;
  39. newCell.localScale = Vector3.one * (1 - border);
  40. newCell.parent = mapHolder;
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement