Playmode turns on the main text automatically

Hi, So… I’m creating this game, and I wanted to add a game over element as a main text for after the health bar gets empty. I turned off the main text in the inspector bar, but whenever i enter play mode, the main text immediately turns on, showing game over before the health bar empties. Is there a way to fix this?

Set the object to inactive. Call SetActive(true) at runtime when there actually is a Game Over. This also prevents the canvas from layouting and rendering the object’s components.

Just disabling the Text component can have unforseen side effects if you ever add more GUI components because this would affect the size of the text element, and thus the layout.

Also consider putting elements that are not always shown together in their own canvas for performance reasons. Although I don’t see that much UI here it’s best practice and may already matter on low-end platforms (eg web). Remember that any change to a GUI element in a canvas forces the entire canvas’ gui elements to relayout which is a costly operation that scales with the number of gui elements in the canvas.