game will not load to gameover when score is reduced

I am nearly finished the main gamplay of my mini game and so far the player can pick up objects and add to the score, the enemy is now shooting at the player and is reducing it to minus the score, but what i want to do is when the player gets hit -10 times by the bullet i want it to load t game over but its not working please see code below i bet there may be a stupid thing i maybe missing somewhere, thanks again guys :slight_smile:

void OnTriggerEnter (Collider hitme)
{
		if(hitme.tag == "pickup")  //found the object to pickup 
		{
			scoreMe += 1;  // add 1 to the score 
			scoreText = "Score: " + scoreMe; // display the score and add the score on the screen 
			Destroy(hitme.gameObject);  // once player collides with the object remove from the scene 
		}
		if(scoreMe > 10)  // if i have collected more than ten pickups 
		{
			Application.LoadLevel(2);	 // Load scene 2
		}
		else
			if(hitme.tag== "bullet")   // player has been hit by bullet 
		{
			
			reducScore --;  // take the current score to minus the score 
			scoreText = "Score:" + reducScore; // display on screen 
			
		}
		else
			if(reducScore > -10)  // once it gets to minus 10
		{
				Application.LoadLevel(3); // load to gameover screen 
		}
				
		
		 // this is where if a player gets hit by an enemy or a explosion you could decrement the score to 0 and maybe 
		// game over screen is displayed when it has reached 0

you have too many elses
with this script, each time an object enters the trigger, only one of the bottom 3 outcomes can happen
either it loads scene 2 OR you reducScore, OR you load scene 3

the load(2) should be inside the pickup tag if
the load(3) should be inside the bullet tag if

This should work :slight_smile:

void OnTriggerEnter (Collider hitme)

{

        if(hitme.tag == "pickup")  //found the object to pickup 

        {

            scoreMe += 1;  // add 1 to the score 

            scoreText = "Score: " + scoreMe; // display the score and add the score on the screen 

            Destroy(hitme.gameObject);  // once player collides with the object remove from the scene 

        }

        if(scoreMe > 10)  // if i have collected more than ten pickups 

        {

            Application.LoadLevel(2);    // Load scene 2

        }

        else

            if(hitme.tag== "bullet")   // player has been hit by bullet 

        {

            

            reducScore --;  // take the current score to minus the score 

            scoreText = "Score:" + reducScore; // display on screen 

            

        }

        else

            if(reducScore < -10)  // once it gets to minus 10

        {

                Application.LoadLevel(3); // load to gameover screen 

        }

                

        

         // this is where if a player gets hit by an enemy or a explosion you could decrement the score to 0 and maybe 

        // game over screen is displayed when it has reached 0

Hi Hpjohn and aaro4130,

Thanks for the feeback, hpjohn can you show me what you mean
:wink:

did you mean something like this

if(hitme.tag== "bullet")   // player has been hit by bullet 
  {


 
 reducScore --;  // take the current score to minus the score 

scoreText = "Score:" + reducScore; // display on screen 

if(reduceScore < -10)
{

Application.LoadLevel(3); // load to gameover screen 

 }

:smile:

Cmon seriously?

He means that you don’t understand the logic behind the if statement. Read the examples here and here. You need to understand the flow of data in your program to avoid unwanted behaviour. I found making simple 'console window ’ text based rpgs helped me understand the flow of data a lot more.

Try using an ‘else if’ instead of ‘else’.

if( this happens)
{
Do this.
}
else if( the first condition doesn’t happen, but this one does)
{
Do this.
}
else //If no condition above happens(no condition for else)
{
Do this.
}