26 lines
708 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|