Advertisement
Guest User

Untitled

a guest
Nov 17th, 2024
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using UnityEngine;
  2. using Unity.Tutorials.Core;
  3.  
  4. public class DontDestroyOnLoad : MonoBehaviour
  5. {
  6. public GameObject[] managedObjects;
  7. private bool isOriginal = false;
  8.  
  9. void Awake()
  10. {
  11. // Check for existing instances
  12. if (!foundOriginal)
  13. {
  14. isOriginal = true;
  15. DontDestroyOnLoad(gameObject);
  16.  
  17. foreach (GameObject obj in managedObjects)
  18. {
  19. if (obj != null)
  20. {
  21. // Remove SceneObjectGuid components
  22. SceneObjectGuid[] guids = obj.GetComponentsInChildren<SceneObjectGuid>(true);
  23. foreach (SceneObjectGuid guid in guids)
  24. {
  25. DestroyImmediate(guid);
  26. }
  27.  
  28. DontDestroyOnLoad(obj);
  29. }
  30. }
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement