code doesnt accept a variable?

i have 2 possible conditions for a code to be executed
one is if health is 0 or below, the other is if fuel is 0 or below

it works fine if health is 0, but it doesnt want to execute the code if fuel is 0 or less

so i made a variable that turns true if health or fuel is 0 or below, and it does this just fine for the both of them
so now i made the code run if this variable is true, and again it works just fine if health is the one that turned it to true, but if fuel was the one that turned it true then it refuses to run the code

i have no idea whatsoever what is going on here anymore, hopefully someone has some sugestions for me

Hello there, can you post your code?

static var fuel : int = 200;
static var health : int = 5;

function update()
{
   if(health == 0)
   {
      health1.renderer. enabled = false;
      health2.renderer. enabled = false;
      health3.renderer. enabled = false;
      health4.renderer. enabled = false;
      health5.renderer. enabled = false;
      gameover = true;
   }

   if(fuel <= 0)
   {
      flyActive = 2;
      gameover = true;
   }
}

and in another script

if(Player.gameover == true  Player.hoogte <= -6)
{
   //do something
}

Player.hoogte refers to a variable holding the current y position of a object btw, but that matches the condition aswell

Don’t have Unity3D installed on this machine but can you try correcting function update to function Update (upper case Update). I am still looking at it :slight_smile:

meh, i just rewrote that here because those two pieces of code are way below in the update function
it is upper case is the original code

the real problem is that despite all conditions being true, the code doesnt get executed
and im sure its because of the fuel variable, why though i have no idea

From what you have posted it looks to me like there is a logic error somewhere else in your code as I can’t see anything wrong with the code I see here…

Why are you checking the conditions in Update? I assume you have a function somewhere that handles the fuel. You can toggle gameover there when it hits zero. Same goes for health.

kinda fixed it by setting health to 0 if fuel is equal or below 0

thanks for your reply though

The reason must be your code implication. Remember, not forcing but by experience says, try coming up with simple solutions when coding for any kind of behavior you want, guess you’re new to scripting.

SOLUTION >
In your code you’re making two if calls that check if health is zero AND fuel is zero but what you really want is to make ONE if statement that makes var gameover == zero IF health OR fuel is equal to zero. don’t get it? follow along:
your script first checks every frame(not a problem here though) if health is zero assume it is zero following that the player ped died and in the same frame it checks if the fuel is zero let’s assume it is not and hence unity will sign off (as the frame ends i.e fraction of a second) the var gameover as false because it doesn’t fulfill the second condition. What you must do then? yeah, it’s below:
you must tell unity via code to not give a damn if both (health and fuel) are zero just set boolean gameover to true if any ONE OF THEM are zero. How to? again, below:

static var fuel : int = 200;
static var health : int = 5;

function update()
{
if(health == 0 || fuel ==0)
{
health1.renderer. enabled = false;
health2.renderer. enabled = false;
health3.renderer. enabled = false;
health4.renderer. enabled = false;
health5.renderer. enabled = false;
gameover = true;
}

else
{
Debug.Log(“this fellow gave you wrong answer! check if someone else posted better… why people even post if they don’t know what they’re posting!”);
}
}

this my breda can be mind bending but if you wanna code unity know how unity behaves for particular function or call!