//Awake is called after all objects are initialized so you can safely speak to other objects or query them using for example GameObject. void Awake() { //if one doesn't exist if (Instance == null) { //set this object as the static instance Instance = this; //make this object stay whenever loading a new scene DontDestroyOnLoad(gameObject); } else { //an instance already exists so destroy this object Destroy(gameObject); } textObject = GameObject.Find("ScoreText").GetComponent <Text>(); hpBar = GameObject.Find("fronthp").GetComponent <Image>(); heart = GameObject.Find("heartImage").GetComponent <Image>(); }
void Awake() { //If an UIManager exists and it is not this... if (current != null && current != this) { //...destroy this and exit. There can be only one UIManagerSingleton Destroy(gameObject); return; } //This is the current UIManager and it should persist between scene loads current = this; Color blackwithalpha = new Color(0.0f, 0.0f, 0.0f, 1.0f); current.blackFadeImage.color = blackwithalpha; // current.blackFadeImage.canvasRenderer.SetAlpha(0.0f); DontDestroyOnLoad(gameObject); }