Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Tilemaps;
- public class LevelManager : MonoBehaviour {
- private Tile[] tiles;
- private Tilemap[] layers;
- private GameObject map;
- private GameObject player;
- private GridLayout gridLayout;
- void LoadTiles(string name)
- {
- tiles = Resources.LoadAll<Tile>("Tilesets/" + name);
- }
- void GenerateRoom()
- {
- for (int x = 0; x < 20; x++)
- {
- for (int y = 0; y < 8; y++)
- {
- layers[0].SetTile(new Vector3Int(x, y, 0), tiles[1]);
- }
- }
- for (int x = 1; x < 19; x++)
- {
- for (int y = 1; y < 7; y++)
- {
- layers[0].SetTile(new Vector3Int(x, y, 0), tiles[0]);
- }
- }
- }
- void AddPlayer()
- {
- player = Resources.Load<GameObject>("Prefabs/player");
- Instantiate(player);
- player.transform.position = gridLayout.CellToWorld(new Vector3Int(3,3,0));
- }
- // Use this for initialization
- void Start() {
- map = GameObject.Find("Map");
- gridLayout = map.GetComponent<Grid>();
- layers = new Tilemap[3];
- for (int i = 0; i < layers.Length; i++)
- {
- layers[i] = map.transform.GetChild(i).GetComponent<Tilemap>();
- }
- LoadTiles("Cave");
- GenerateRoom();
- AddPlayer();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement