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 TileManager : MonoBehaviour {
- public Dictionary<Vector2, Tile> tiles;
- public GameObject prefabTile;
- public int worldSizeX = 10;
- public int worldSizeY = 10;
- void Start () {
- tiles = new Dictionary<Vector2, Tile>();
- GenerateWorld();
- }
- public void GenerateWorld()
- {
- for (int x = 0; x < worldSizeX; x++)
- {
- for (int y = 0; y < worldSizeX; y++)
- {
- Vector2 intPosition = new Vector2(x, y);
- Vector3 worldPosition = new Vector3(x, y, 0);
- GameObject tileGO = Instantiate(prefabTile, worldPosition, Quaternion.identity, transform);
- tiles.Add(intPosition, tileGO.GetComponent<Tile>());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement