Advertisement
Guest User

unity

a guest
Dec 15th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Tilemaps;
  5.  
  6. public class LevelManager : MonoBehaviour {
  7.  
  8.  
  9.     private Tile[] tiles;
  10.     private Tilemap[] layers;
  11.     private GameObject map;
  12.     private GameObject player;
  13.     private GridLayout gridLayout;
  14.  
  15.     void LoadTiles(string name)
  16.     {
  17.         tiles = Resources.LoadAll<Tile>("Tilesets/" + name);
  18.     }
  19.  
  20.     void GenerateRoom()
  21.     {
  22.         for (int x = 0; x < 20; x++)
  23.         {
  24.             for (int y = 0; y < 8; y++)
  25.             {
  26.                 layers[0].SetTile(new Vector3Int(x, y, 0), tiles[1]);
  27.             }
  28.         }
  29.  
  30.         for (int x = 1; x < 19; x++)
  31.         {
  32.             for (int y = 1; y < 7; y++)
  33.             {
  34.                 layers[0].SetTile(new Vector3Int(x, y, 0), tiles[0]);
  35.             }
  36.         }
  37.     }
  38.  
  39.     void AddPlayer()
  40.     {
  41.         player = Resources.Load<GameObject>("Prefabs/player");
  42.         Instantiate(player);
  43.         player.transform.position = gridLayout.CellToWorld(new Vector3Int(3,3,0));
  44.     }
  45.  
  46.  
  47.     // Use this for initialization
  48.     void Start() {
  49.  
  50.         map = GameObject.Find("Map");
  51.         gridLayout = map.GetComponent<Grid>();
  52.         layers = new Tilemap[3];
  53.  
  54.         for (int i = 0; i < layers.Length; i++)
  55.         {
  56.             layers[i] = map.transform.GetChild(i).GetComponent<Tilemap>();
  57.         }
  58.  
  59.         LoadTiles("Cave");
  60.         GenerateRoom();
  61.         AddPlayer();
  62.     }
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement