Game Over text

Hey folks, so I know this code gets the text to show up right away but how do I get it so it only shows up when your lives are less than or equal to zero? Is this the wrong way to do it or will I be able to add to it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;



public class GameOver : MonoBehaviour
{
   
 void OnGUI()
    {

        {
        
                                                              
            }

            {
                GUI.Label(new Rect(500, 500, 100, 20), "Game Over");
            }
          

        }

Start here.

I will try it. But for something totally different, I tried to find a tutorial for this:
How do I do it so not only you need to jump over a game object but you need to jump over it twice to destroy it? I am using Unity 2d.

I found tutorials for jumping on it but not over it.

It’s a really good idea to start off with some tutorials. Sure, maybe you want to play around, as well… that’s all good. The tutorials will help you understand the fundamental pieces, so that you can use them to design your own game well. :slight_smile:

While you may not find a tutorial for “How to jump over an object twice to destroy it” … because that’s very unique/specific!, you will find how to move (eg: jump), how to destroy, and … how to count! :slight_smile:

Also note that it’s not really recommended that you use the GUI for your game’s UI. Try to use the “Create → UI → (stuff)”, other than for some fast prototyping or editor scripts.

To your original question: Using a method that gets called when you lose a life (or lives), you can check at that time to decide whether to take any action based on the remaining number of lives.