Load gameoverscreen after condition. Error

Hi, I will just get straight to the point. I want my gameoverscreen to load after the player hits 20 health or less, this is my code:

function gameover()
{
   if ( PlayerHealth <= 20 )
   Application.LoadLevel("Gameoverscreen");
}

Every time I get this error: Operator ‘<=’ cannot be used with a left hand side of type ‘System.Type’ and a right hand side of type ‘int’.

I hope you guys can help me out :slight_smile:

-Chris

Ok, what the error is saying is that you are trying to compare a Type to an int. A type is ‘int’ itself not the value of int. A script is also considered a type as you can declare a variable of type ‘script’

var scriptVariable : Script; // variable scriptVariable of type Script, where 'Script' is the Actual name of a script
var myNumber : int = 0; // variable myNumber of type int equal to 0

In your case you have a script called PlayerHealth and so your engine recognises it as a type so throws your error when you use it in your if statement comparison.

What you need to do is declare an integer and use that for your players health value.

var playerHP : int = 100;

function gameover()
{
    if ( playerHP <= 20 )
    Application.LoadLevel("Gameoverscreen");
}

In the if statement line

if ( playerHP <= 20 )

playerHP is an integer so the if can make the comparison.

Understand though, I’m simply dealing with the error and not telling you how best to do whatever it is you are trying to do.