/// <summary> /// Runs on controller creation. /// </summary> private void Awake() { // If the object has not been set yet (this object) if (canvas == null) { // Don't EVER destroy this one, and set this object so we have a reference to it later. DontDestroyOnLoad(gameObject); canvas = this; // Reassign the button onClick methods Button[] buttons = this.gameObject.GetComponentsInChildren <Button>(); foreach (Button b in buttons) { if (b.name == "ButtonMenu") { b.onClick.AddListener(LocalPause); } } TextMeshProUGUI[] text = gameObject.GetComponentsInChildren <TextMeshProUGUI>(); foreach (TextMeshProUGUI t in text) { if (t.name == "Timer") { timerText = t; } } } else if (canvas != this) { // If there is an object already stored, and it's not this one, destroy this! Destroy(gameObject); } }
// Update is called once per frame void Update() { if (logo.pulsado) { animacionInicial.SetTrigger("desvanecer"); canvasPrincipal.SetActive(false); CanvasMenu.SetActive(true); } }
void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject);//only one exist } DontDestroyOnLoad(this.gameObject); }
private void Awake() { Instance = Instance ?? this; }
private void Start() { Instance = this; }