max lives

how do i create a max lives on this script because when i pick up lives
it still counts up
and how do i make that i cant pick up health-pickup when i am full-health?
could someone help me ?
this is my healthcontrol:

var health1 : Texture2D; //one live left
var health2 : Texture2D; //two live left
var health3 : Texture2D; //three live left
var health4 : Texture2D; //four live left
var health5 : Texture2D; //full health

static var LIVES = 5;

function Update ()
{
	switch(LIVES)
	{
		case 5:
			guiTexture.texture = health5;
		break;
		
		case 4:
			guiTexture.texture = health4;
		break;
		
		case 3:
			guiTexture.texture = health3;
		break;
		
		case 2:
			guiTexture.texture = health2;
		break;
		
		case 1:
			guiTexture.texture = health1;
		break;
		
		case 0:
		//gameover script here
		break;
	}
}

and here the pickup piece:

private var heart = false;

function OnControllerColliderHit(hit : ControllerColliderHit)
{
		if(hit.gameObject.tag== "heart")
	{
		gotHit = true;
				//Add Lives here !! YEAH !
		HealthControl.LIVES += 1;
		Destroy (hit.collider.gameObject);
	}
}

------------------------------------------
here comes the other piece in same javascript:

function LateUpdate()
{
	if(heart)
	{
		heart = false;
	}
}

That’s a really simple if statement right thar.

if ( life < maxLife ) {
  // pick up object
} else {
  // don't pick up object
}

where do i have to place it and
i dont got any max lives piece in my script so i need that first… ):
could you help me ?

Question : you don’t even remember / see where you write YOURSELF the code line which increase your live count ?!

Vicenti said everything…

no but i dont got any max lives and that from vincenti
where do i have to place that ?
could someone help me ?

You have to add it, how can Vincenti know how many lives you wish your player to have?

It’s a variable. You put it with other variables that it relates to.

And you put the if statement around the part you already have that picks up the object.

ok but what kind of variable do i need how to call it because i dont work…
could you help me >?

You have all the code here :slight_smile: Well, aside from var maxLife = . Vicenti’s code just needs to be put in your pickup code … this is a pretty logical thing to do, and considering the first and second parts of the code you produced, it should be a valuable learning exercise to combine them both. Good Luck! :slight_smile:

ok i gonna try better
when i am done working off some works
i gonna try if i done i will say it
:stuck_out_tongue:

////////////////////////////
i don’t have var life and maxlife
is still need that part

Add them.

Look at the code you already have (you already have LIVES) and observe how variables are declared.

Declare a variable named something that makes sense to you. It will represent the maximum value of LIVES.
Because it is so closely tied to the variable LIVES, it makes good scripting sense to declare it near LIVES, and definitely in the same script as LIVES.

Before attempting to pick up an object, check to see that LIVES is less than your declared maximum value for LIVES.
You attempt to pick up an object in the OnControllerColliderHit function. That is where you perform the check.

I feel that you may wish to read more tutorials if this still doesn’t make sense to you.

i got a little question because i have placed my script in it but i cant pickup health now anymore…
this is the script for now…:
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if ( LIVES < maxLIVES ) {
// pick up object
if(hit.gameObject.tag== “heart”)
{
gotHit = true;
//Add Lives here !! YEAH !
HealthControl.LIVES += 1;
Destroy (hit.collider.gameObject);
}
} else
// don’t pick up object
{
if(heart)
{
heart = false;
}
}
}
and also the two variables:
static var LIVES = 5;
static var maxLIVES = 5;

could someone help me ?
(already thnks to vicenti)

Hey, you are so close to the answer - you have all the bits. Just telling you what to do wouldn’t help you in the future, this is a simple thing, and learning to do it yourself would not only make you feel awesome, it would make you a better coder. You have everything you need.

Looking here might help you with this :

http://www.techotopia.com/index.php/JavaScript_Flow_Control_and_Looping

You already have one if statement in your code learning to combine if statements is pretty important :slight_smile: Just try different things, I am sure you will manage it! :slight_smile:

cant find it at techtopia
i see the if and else statements
but not the part that i want :frowning:

You have this “if” statement:-

if(hit.gameObject.tag== "heart")...

Are you sure the object you want to pick up has a “heart” tag? If you click on the tag menu in the inspector, you can add new tags, which you will need to do in this case.

thanks all i found a another forum who fixed for me
but you all helped me allot !
thank you