- Home /
Random Generated Dungeon Issue
So what I'm trying to do is make an FPS where you go through randomly generated dungeons to reach the boss. The only problem is that occasionally, a door will spawn with a wall covering the other end. There is a possible solution but I don't know how to add it to my code. The solution would be to destroy it and spawn it again to get a different dungeon piece and see if that fits all the doorways.
Here is my code:
using UnityEngine;
public class SpawnPoint : MonoBehaviour
{
public int OpeningDirection;
// 2 = bottom
// 1 = top
// 4 = left
// 3 = right
private RoomTemplates templates;
private int rand;
private bool spawned = false;
private void Start()
{
templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent<RoomTemplates>();
Invoke("Spawn", 0.1f);
}
private void Spawn()
{
if (spawned == false)
{
if (OpeningDirection == 2)
{
rand = Random.Range(0, templates.bottomRooms.Length);
Instantiate(templates.bottomRooms[rand], transform.position, templates.bottomRooms[rand].transform.rotation);
}
else if (OpeningDirection == 1)
{
rand = Random.Range(0, templates.topRooms.Length);
Instantiate(templates.topRooms[rand], transform.position, templates.topRooms[rand].transform.rotation);
}
else if (OpeningDirection == 4)
{
rand = Random.Range(0, templates.leftRooms.Length);
Instantiate(templates.leftRooms[rand], transform.position, templates.leftRooms[rand].transform.rotation);
}
else if (OpeningDirection == 3)
{
rand = Random.Range(0, templates.rightRooms.Length);
Instantiate(templates.rightRooms[rand], transform.position, templates.rightRooms[rand].transform.rotation);
}
spawned = true;
}
}
// This is to stop dungeon parts from spawning into each other
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("SpawnPoint") && other.GetComponent<SpawnPoint>().spawned == true)
{
Destroy(gameObject);
Debug.Log("Destroyed");
}
if (other.gameObject.CompareTag("Floor"))
{
Destroy(gameObject);
Debug.Log("Delete");
}
}
}
If any of you know a possible solution to fix my problem, please put it down.
Error:
pls-halp-me.png
(38.7 kB)
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do i Achieve mesh Extrusion? 2 Answers
Can I make a collider ignore only one other collider? 0 Answers
knockback 3d c# 1 Answer