DestoryOnLoad.cs 477 B

123456789101112131415161718192021222324
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. namespace Rokid.UXR.Utility
  4. {
  5. public class DestoryOnLoad : MonoBehaviour
  6. {
  7. private void Awake()
  8. {
  9. SceneManager.sceneUnloaded += OnSceneUnLoaded;
  10. }
  11. private void OnDestroy()
  12. {
  13. SceneManager.sceneUnloaded -= OnSceneUnLoaded;
  14. }
  15. private void OnSceneUnLoaded(Scene scene)
  16. {
  17. Destroy(this.gameObject);
  18. }
  19. }
  20. }