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 MapGenerator : MonoBehaviour {
- public Transform cellPerf;
- public Vector2 mapSize;
- [Range(0,1)]
- public float border;
- void Start () {
- GeneratorMap ();
- }
- void Update () {
- }
- public void GeneratorMap()
- {
- string holderName = "GeneratedMap";
- if (transform.FindChild (holderName))
- {
- DestroyImmediate (transform.FindChild (holderName).gameObject);
- }
- Transform mapHolder = new GameObject (holderName).transform;
- mapHolder.parent = transform;
- for(int x = 0; x< mapSize.x; x++)
- {
- for(int y = 0; y< mapSize.y; y++)
- {
- Vector3 cellPosition = new Vector3(-mapSize.x/2 + 0.5f + x, 0, -mapSize.y/2 + 0.5f +y);
- Transform newCell = Instantiate(cellPerf, cellPosition, Quaternion.Euler(Vector3.right*90)) as Transform;
- newCell.localScale = Vector3.one * (1 - border);
- newCell.parent = mapHolder;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement