Clear NPC Chatbox UI

Reply by petroslouca | 2024-10-15 22:10:09

Unfortunately that did not work for me, I used the following function to iterate and destroy each chatbox message:

public void DestroyAllChatBoxUIMessages()
    {
        // Find the ChatBox's child GameObject "Content"
        GameObject chatBox = GameObject.Find("Content");

        if (chatBox != null)
        {
            // Loop through each child of the ChatBox
            foreach (Transform child in chatBox.transform)
            {
                // Check if the child's name is "ChatBox(Clone)"
                if (child.gameObject.name == "ChatBox(Clone)")
                {
                    // Destroy the child GameObject
                    Destroy(child.gameObject);
                }
            }

            Debug.Log("All ChatBox(Clone) gameobjects destroyed!");
        }
        else
        {
            Debug.LogWarning("ChatBox(Clone) GameObject not found.");
        }
    }