Placido_GDD

MVC Roguelike Room Gen

Jan 13th, 2022 (edited)
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GenerateRooms : MonoBehaviour
  6. {
  7.     public int MaxRoomCount;
  8.     private RoomTemplates templates;
  9.     private int rand;
  10.     //1:need bottom door
  11.     //2:need top door
  12.     //3:need left door
  13.     //4:need right door
  14.     public List<RoomInfo> roomProp = new List<RoomInfo>();
  15.     public List<GameObject> Rooms = new List<GameObject>();
  16.    
  17.     // Start is called before the first frame update
  18.     void Start()
  19.     {
  20.         templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent<RoomTemplates>();
  21.         Invoke("InitialRooms", 0.1f);
  22.     }
  23.  
  24.     private void Update()
  25.     {
  26.        
  27.        
  28.     }
  29.  
  30.    
  31.     void InitialRooms()
  32.     {
  33.        for (int i = 0; i < Rooms.Count; i++)
  34.         {
  35.             if (roomProp[i].RoomType == 1)
  36.             {
  37.                 rand = Random.Range(0, templates.bottomRooms.Length);
  38.                 Instantiate(templates.bottomRooms[rand],Rooms[i].transform.position, Quaternion.identity);
  39.             }
  40.             if (roomProp[i].RoomType == 2)
  41.             {
  42.                 rand = Random.Range(0, templates.topRooms.Length);
  43.                 Instantiate(templates.topRooms[rand], Rooms[i].transform.position, Quaternion.identity);
  44.             }
  45.             if (roomProp[i].RoomType == 3)
  46.             {
  47.                 rand = Random.Range(0, templates.leftRooms.Length);
  48.                 Instantiate(templates.leftRooms[rand], Rooms[i].transform.position, Quaternion.identity);
  49.             }
  50.             if (roomProp[i].RoomType == 4)
  51.             {
  52.                 rand = Random.Range(0, templates.rightRooms.Length);
  53.                 Instantiate(templates.rightRooms[rand], Rooms[i].transform.position, Quaternion.identity);
  54.             }
  55.         }
  56.        
  57.     }
  58.     public void SpawnRoom(Vector3 roomPos,bool spawnedRoom,int roomType)
  59.     {
  60.         if (spawnedRoom == false)
  61.         {
  62.             switch (roomType)
  63.             {
  64.                 case 1:
  65.                     rand = Random.Range(0, templates.bottomRooms.Length);
  66.                     Instantiate(templates.bottomRooms[rand], roomPos, Quaternion.identity);
  67.                     break;
  68.                 case 2:
  69.                     rand = Random.Range(0, templates.topRooms.Length);
  70.                     Instantiate(templates.topRooms[rand], roomPos, Quaternion.identity);
  71.                     break;
  72.                 case 3:
  73.                     rand = Random.Range(0, templates.leftRooms.Length);
  74.                     Instantiate(templates.leftRooms[rand],roomPos, Quaternion.identity);
  75.                     break;
  76.                 case 4:
  77.                     rand = Random.Range(0, templates.rightRooms.Length);
  78.                     Instantiate(templates.rightRooms[rand], roomPos, Quaternion.identity);
  79.                     break;
  80.                 case 0:
  81.                     Instantiate(templates.ClosedRoom,roomPos, Quaternion.identity);
  82.                     break;
  83.             }
  84.  
  85.         }
  86.  
  87.     }
  88.  
  89. }
Add Comment
Please, Sign In to add comment