From 75123d8312a077e9073b18d82f8fe79518adc654 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sat, 18 Oct 2025 10:22:09 -0700 Subject: [PATCH] thanks chatgpt, I don't even know what was wrong :skull: --- Assets/Scripts/ChatroomMenu.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/ChatroomMenu.cs b/Assets/Scripts/ChatroomMenu.cs index 736c19f..468582b 100644 --- a/Assets/Scripts/ChatroomMenu.cs +++ b/Assets/Scripts/ChatroomMenu.cs @@ -407,10 +407,17 @@ public class ChatroomMenu : MonoBehaviour } obj.SetSiblingIndex(i); } - if (content.transform.childCount > 50) + int activeCount = content.transform.Cast().Count(t => t.gameObject.activeSelf); + if (activeCount > 50) { - var firstChild = content.transform.GetChild(1); - Destroy(firstChild.gameObject); + int toRemove = activeCount - 50; + foreach (Transform item in content.transform) + { + if (!item.gameObject.activeSelf) continue; + Destroy(item.gameObject); + toRemove--; + if (toRemove <= 0) break; + } } var rowInfo = Instantiate(sampleObject, content.transform); @@ -483,10 +490,9 @@ public class ChatroomMenu : MonoBehaviour { foreach (Transform item in content.transform) { - if (item.gameObject.activeSelf) - { - Destroy(item.gameObject); - } + if (!item.gameObject.activeSelf) continue; + Destroy(item.gameObject); + break; } } if (shouldScrollToBottom)