From 123d47f6fff77e21c1f393196ca01ec2f19ac0e3 Mon Sep 17 00:00:00 2001
From: Robin Ruud Kristensen <robin1998@hotmail.no>
Date: Fri, 9 Dec 2022 11:18:02 +0100
Subject: [PATCH] fix looped generation. Fix: reset stair_down value to false
 and destroying existing stairs

---
 MrBigsock/Assets/Code/FollowPlayer.cs | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/MrBigsock/Assets/Code/FollowPlayer.cs b/MrBigsock/Assets/Code/FollowPlayer.cs
index bd91e282..79d41e40 100644
--- a/MrBigsock/Assets/Code/FollowPlayer.cs
+++ b/MrBigsock/Assets/Code/FollowPlayer.cs
@@ -41,27 +41,36 @@ namespace Bigsock
                 c.SetActive(false);
             }
             stairs_down = stair.GetComponent<Stairs>().stairs_touch;
+            stair.SetActive(false);
         }
 
         void LateUpdate()
         {
             boss = GameObject.FindGameObjectsWithTag("Boss");
             enemies = GameObject.FindGameObjectsWithTag((roomNr).ToString());
-            stairs_down = stair.GetComponent<Stairs>().stairs_touch;
+            if (boss.Length == 0 && levels <= 1)
+            {
+                stair.SetActive(true);
+                stairs_down = stair.GetComponent<Stairs>().stairs_touch;
+            }
+            
 
-            if (boss.Length == 0 && levels <= 1 && stairs_down)
+            if (stairs_down)
             {
                 roomNr = 0;
                 foreach(GameObject c in chests)
                 {
                     Destroy(c);
                 }
+                DestroyImmediate(stair);
                 chests.Clear();
                 TilemapGenerator.resetMaps();
                 TilemapGenerator.SetRoomIDZero();
                 player.transform.position = new Vector3(9,5,0);
                 neighborMapGenerator.RunProceduralGeneration();
                 Chest = GameObject.FindGameObjectsWithTag("Chest");
+                stair = GameObject.Find("Stairs(Clone)");
+                stairs_down = stair.GetComponent<Stairs>().stairs_touch;
                 foreach (GameObject c in Chest)
                 {
                     if(c != null)
@@ -70,6 +79,7 @@ namespace Bigsock
                         chests.Add(c);
                     }
                 }
+                stair.SetActive(false);
                 levels++;
             }
 
-- 
GitLab