I am trying to make a Dungeon following a perlin noise cluster, but only in 1 cluster, not the whole room. so I made a self duplicating stucture that should delete themselfs after spreading, and should die out after expanding to the size of a cluster.
But for some reason, I get an infinite loop. It doubles back on itsef, and does not get deleted once it does that.
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoomGen : MonoBehaviour
{
public float RoomValue;
public float seed = 1.457582f;
public GameObject Marker;
public GameObject Self;
// Start is called before the first frame update
void Start()
{
}
void LateUpdate()
{
RoomValue = Mathf.PerlinNoise(transform.position.x * seed, transform.position.z * seed);
if (RoomValue >= .4f)
{
Instantiate(Marker, transform.position, transform.rotation);
Instantiate(Self, transform.position + new Vector3(-1, 0 ,0), transform.rotation);
Instantiate(Self, transform.position + new Vector3(1, 0, 0), transform.rotation);
Instantiate(Self, transform.position + new Vector3(0, 0, -1), transform.rotation);
Instantiate(Self, transform.position + new Vector3(0, 0, 1), transform.rotation);
Destroy(this.gameObject);
}
else
{
Destroy(this.gameObject);
}
}
private void OnCollisionStay(Collision collision)
{
Destroy(this.gameObject);
}
}