health control

hi little people that make strange and happy funny things.

I want to know if this script is right:

var health1 : Texture2D;
var health2 : Texture2D;
var health3 : Texture2D;

static var LIVES = 3;

function Update () 
{
		switch(LIVES)
		{
			case 3:
				guiTexture.texture = health3;
			break;
			
			case 2:
				guiTexture.texture = health2;
			break;
			
			case 1:
				guiTexture.texture = health1;
			break;
			
			case 0:
					if(LIVES == 0){
						Application.Quit();}
			break;
		}
}

you can remove the if condition:

if(LIVES == 0)

it isn’t required since the switch clause is already checkin it.

It works if it gives you the results you want.

We don’t know what you are looking for, so we have no idea if it works for you.

What Dman said. It really depends on what you define as “right”. Is the script supposed to spawn unicorns at random intervals? Then no, its not right.

What do you want the script to do?

I want to the game end when I don’t have more any lives

lol!!

this is a idiot…

Back at ya! You might want to actually answer his question:

“What do you want your script to do?”

Rather than insult people. Your much less likely to get help that way…

my thread isn’t a place to laugh the others, like you did

"is the script supposed to spawn unicorns at random intervals? Then no, its not right.

lol"

I was laughing at his comment. Not your request.

(you should probably still answer the question, unless you have your answer already)

And I apologize if my laughing at his comment offended you

Remove the if(Lives==0)

and add a default: and do QUIT from the default case too. Hope this work around works for you :slight_smile:

Don’t quit from the default case. If your game is getting into a state you don’t expect like negative lives then it’s better you know about it. Add

Debug.LogError("OMG something I didn't expect.");

Oh and another thing, you don’t need to do it every frame in update(). Instead you only have to check lives each time lives changes.