Advertisement
Guest User

Untitled

a guest
May 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TileManager : MonoBehaviour {
  6.  
  7.     public Dictionary<Vector2, Tile> tiles;
  8.     public GameObject prefabTile;
  9.     public int worldSizeX = 10;
  10.     public int worldSizeY = 10;
  11.  
  12.     void Start () {
  13.         tiles = new Dictionary<Vector2, Tile>();
  14.         GenerateWorld();      
  15.     }
  16.  
  17.     public void GenerateWorld()
  18.     {
  19.         for (int x = 0; x < worldSizeX; x++)
  20.         {
  21.             for (int y = 0; y < worldSizeX; y++)
  22.             {
  23.                 Vector2 intPosition = new Vector2(x, y);
  24.                 Vector3 worldPosition = new Vector3(x, y, 0);
  25.                 GameObject tileGO = Instantiate(prefabTile, worldPosition, Quaternion.identity, transform);
  26.                 tiles.Add(intPosition, tileGO.GetComponent<Tile>());
  27.  
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement