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

Unity C# Singleton?

$
0
0
I'm trying to make a simple singleton object, basically just exists and spams the console that it exists so I can confirm it works when switching scenes (using Application.LoadLevel(Scene)). This doesn't work yet, the Debug.Log fails to continue when loading the new scene and I'm kinda stuck. All the examples I've seen for Singletons look similar to this, just kinda banging my head into a wall. Any ideas? using UnityEngine; using System.Collections; public class SimpleSingleton : MonoBehaviour { private static SimpleSingleton instance = null; // Game Instance Singleton public static SimpleSingleton Instance { get { return instance; } } private void Awake() { // if the singleton hasn't been initialized yet if (instance != null && instance != this) { Destroy(this.gameObject); } instance = this; DontDestroyOnLoad( this.gameObject ); } void Update() { Debug.Log( "SINGLETON UPDATE" ); } }

Viewing all articles
Browse latest Browse all 416

Trending Articles



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