Door Tags C Sharp

Hey all. So in my game I have two scripts. One for the door manager and the door. In the game, the player can select one of 4 doors, one of them being the one that kills him. However, when the wrong door is selected, instead of loading scene 1, the death scene, it loads scene 2, which progresses in the game. Is there a way I can use tags or something to detect that it is the kill door? I’m terrible with C Sharp.

using UnityEngine;
using System.Collections;

public class Door: MonoBehaviour {
	public bool killDoor = false;
	
	// When player choose the door, pass the parameter here.
	void OnMouseDown ()
	{
		if ( killDoor )
		{
			Application.LoadLevel (1);
			print ( "Game over" );
		}

		else
			print ( "Success!" );
			Application.LoadLevel (2);

	}
}

You don’t have any {} brackets on your else statement, which means your code blocks aren’t actually doing what you expect.

You want this:

    if ( killDoor )
    {
        Application.LoadLevel (1);
        print ( "Game over" );
    }

    else
    {
        print ( "Success!" );
        Application.LoadLevel (2);
    }

If you don’t include the brackets, an if or else applies only to the very next statement, rather than an entire block. Because of that, your LoadLevel(2) call was being triggered no matter what happened.