Quantcast
Channel: Questions in topic: "dontdestroyonload"
Viewing all articles
Browse latest Browse all 416

Destroy object with dontdestroyonload

$
0
0
Hi, I have some script that is attached to an object so that it isn't destroyed as you play through level 1, level 2, level 3 and so on. However I want this object to be destroyed when the player reaches the menu screen, I've tried some if statements, something like if (SceneManager.LoadScene = "sceneSelectBeta") { Destroy; } And tried adding some destroy functions but I can't get the object to delete when it reaches the scene. Here is the code attached to the object, any help or advice would be appreciated. using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class clockDontDestroy : MonoBehaviour { private static clockDontDestroy _instance = null; public static clockDontDestroy Instance { get { return _instance; } } void Awake() { if (_instance != null && _instance != this) { Destroy(transform.root.gameObject); return; } _instance = this; DontDestroyOnLoad(transform.root.gameObject); } }

Viewing all articles
Browse latest Browse all 416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>