Files
Savina Rizdafayi d7120c397a Initial commit
2025-07-12 19:53:40 +07:00

26 lines
708 B
C#

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.EventSystems;
public class Penghapus : MonoBehaviour
{
void Start()
{
string currentScene = SceneManager.GetActiveScene().name;
// Hapus canvas & EventSystem yang BUKAN dari scene aktif
foreach (GameObject go in Object.FindObjectsByType<GameObject>(FindObjectsSortMode.None))
{
if (!go.scene.name.Equals(currentScene))
{
if (go.GetComponent<Canvas>() || go.GetComponent<EventSystem>())
{
Debug.Log("Destroy leftover UI: " + go.name);
Destroy(go);
}
}
}
}
}