- Home /
Question by
importguru88 · Jun 16, 2016 at 09:21 AM ·
c#destroyloadsingleton
Where would I call the DoDestroyOnLoad function on my Singleton Script
I need to load my scene . The singleton script is attach to a UI text . I gotten an error when I have the destroyonload. Here is my script :
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class GameManagerSingleton : MonoBehaviour { public static GameManagerSingleton instance = null;
public static int score;
private Text text;
void Awake()
{
text = GetComponent <Text> ();
score = 0;
if (instance != null && instance != this)
Destroy(gameObject); // Ensures that there aren't multiple Singletons
instance = this;
}
void Update()
{
text.text = "Score: " + score;
Debug.Log("Score: " + score);
}
}
Comment
Answer by Brijs · Jun 16, 2016 at 09:51 AM
Use Unity Wiki Singleton Script
You will not have to take care of anything.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Using Singleton but getting a null reference 2 Answers
Distribute terrain in zones 3 Answers
My scene won't load! 1 Answer
Load Script on Game Start 1 Answer