Guest User

Untitled

a guest
May 17th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Globals : MonoBehaviour
  7. {
  8.  
  9.     public static Globals instance;
  10.  
  11.     public string roomID;
  12.     public List<Room> rooms;
  13.  
  14.     private void Awake()
  15.     {
  16.         if (instance == null)
  17.         {
  18.             instance = this;
  19.         }
  20.         else if (instance != this)
  21.         {
  22.             Destroy(gameObject);
  23.         }
  24.  
  25.         DontDestroyOnLoad2(gameObject);
  26.  
  27.     }
  28.  
  29.     private void DontDestroyOnLoad2(GameObject myObj)
  30.     {
  31.         Transform parentTransform = myObj.transform;
  32.  
  33.         while (parentTransform.parent != null)
  34.         {
  35.             parentTransform = parentTransform.parent;
  36.         }
  37.  
  38.         GameObject.DontDestroyOnLoad(parentTransform.gameObject);
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment