Hooking up the canvas more cleanly

Rick has said its a little sloppy to hook up the game over canvas as he had because if you are in different levels you would have to do it manually.

I wrote a bit of code that should work to auto hook things up.
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class DeathHandler : MonoBehaviour


GameObject gameOverCanvas;

void Start()


    gameOverCanvas = GameObject.FindGameObjectWithTag("GameOverUI");

    gameOverCanvas.GetComponent<Canvas>().enabled = false;



essentially instead of making a canvas object i made a gameobject, used the findgameobject with tag function and tagged my game over ui with it. then I used getcomponent to access the canvas part of it and set that to false.


Privacy & Terms