Need help on GUIs asap

Sorry,

But I have been searching and reading and just not finding an able way to set up this script to pass this class. All I ask is any help on my main objective is all appreciated.

I have a PlayerHealth (hp manager) script attached to the main controller (named “Player”). This script allows me to have a small lifebar at the top left screen of the game window. It allows health to deducted by 1 point when hit from and object tagged with “Npc”.
It looks like this in c#:

public class PlayerHealth : MonoBehaviour {
public int maxHealth = 2;
	public int curHealth = 2;
	public int damage = 1;
	
public bool hit = false;
	
	void Start () {
	}
	
	void Update () {
	}	
	
	void OnGUI () {
GUI.Box (new Rect(10,10,Screen.width / 2 / (maxHealth/curHealth), 20),curHealth + "/" + maxHealth);
	}
	
	void OnTriggerEnter(Collider Enter) {
		if(Enter.CompareTag ("Npc")) {
			curHealth -= damage;
			hit = true;
		} else {
			hit = false;
		}
	}
}

I need help on creating a GUI text that says You Lose!

When curHealth =0.
No matter what I try I run into errors. I don’t know if it’s how or what I attached to what object. I made a GUI object and wrote in the valid text, and have it parented under the Player.
I also have a window script that pops up to clickable buttons with different colors. One for reload and one for quit.

It looks like this in c#:
public class Windows : MonoBehaviour {

public Rect windowRect0 = new Rect(20, 20, 120, 50);
public Rect windowRect1 = new Rect(20, 100, 120, 50);	
	
	void Start () {
	
	}
	
	void Update () {
	
	}
	 
	void OnGUI() {
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Quit");
        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Restart");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Click"))
            print("Got a click in window with color " + GUI.color);
        
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}

How would I get these windows to only pop up after the GUI “You Lose!” is triggered?
And/or know how to script in a reload attached to that button and a basic GUI text attached to the exit button that says Game Over.

I will continue on my crazy search for my own methods, but I would be extremely grateful for any help.
Thank you all in advance.

Sorry, you’ve asked a lot of questions and your code didn’t come out formatted properly. I’ll try to answer your first one: how do I make a GUI text that says “You Lose” when the player’s health is zero?

There are two ways I would accomplish this: with a new script attached to the GUIText object that checks the value of curHealth on the PlayerHealth component; or adding a reference to the GUIText to the PlayerHealth script and controlling it from there. I will detail the second solution below.

Add a public field that will be a reference to the GUIText to PlayerHealth

public GUIText gameOverText;

In the inspector, drag your game over GUIText to the new field on the PlayerHealth script. Add the following to PlayerHealth’s Update method and you should be good to go:

	void Update () {
		if (curHealth <= 0) {
			gameOverText.enabled = true;
		} else {
			gameOverText.enabled = false;
		}
	}

Hope this helps