How to make player lose lives?

I’m making a 2d platformer, and I want the player to lose lives when he dies. Here’s what I’ve got so far:

public var Lives = 3;

public function OnGUI() {
	(GUI.Button (Rect ( 10, 50, 100, 30 ), "Lives: "  + Lives));

public function OnTriggerEnter (hit : Collider) : IEnumerator {
	if (hit.collider.tag == "DeathZone") {
	Lives = Lives - 1;

Also how would I print the number of lives onto the screen without using a GUI.Button? Sorry I’m pretty new to this. :slight_smile:

You are decreasing lives @line: 12, but before that “Application.LoadLevel(0)” will load the level again. Hence, your script which holds the Lives var will also get reset and your player never looses lives.

You have to separate the Lives data from this class or do not use Application.LoadLevel().

See how you can manage and come up with new code blocks if you still face the problem.

You can display the information using GUI.Label. @appearance is right about your data getting reset each time you do an Application.LoadLevel(). If you want to continue to use this method, take a look at Object.DontDestroyOnLoad().

There are lots of cheap plugins out there that will help integrate lives in your game very easily. I recommend “Life System Pro - Easy Lives Integration for Freemium Games” found here Unity Asset Store - The Best Assets for Game Making