FPS Styled Timer Game: Script for starting a timer on play and stopping the timer when win condition achieved.

I have a basic FPS game where I have targets all over the level with the same tag so that I can use:

if (GameObject.FindWithTag(“Target”) == null) {
//Stop timer on GUI and print “All targets were destroyed, you win!”
// Press X to Quit or Spacebar to Restart

I’m fairly inexperienced with coding, so I don’t know how to start a timer on game start or make it update in real time on the GUI. I also don’t know how to implement the “Press X to Quit or Spacebar to Restart.” Neither on the GUI or the actual functions.

All other game mechanics are functional, so the targets destroy when shot twice etc.

If anyone has experience in this field who can help me script in C# your help would be most appreciated!

Don’t ask people to write you code.

public Text timerUIText;
public float currentTime;

void Update ()
{
	currentTime += Time.deltaTime;
	
	if (GameObject.FindWithTag("Target") == null) 
	{ 
		timerUIText.text = "All targets were destroyed, you win! 

Press X to Quit, or Spacebar to Restart";
}
else
{
timerUIText.text = "Time: " + currentTime;
}
}

But I’ll write it for you this time. Remember to include the UnityEngine.UI; namespace in your script.
(Add this to the top of your script) using UnityEngine.UI;