Switching Scene Immediately

Hello! I have a script I am using to Switch the scene once my player is hit by the enemy. Instead, the scene switches when I hit play.

Here is my script:

public class DestroyPlayer : MonoBehaviour {

void OnTriggerEnter(Collider other) {
	if (other.gameObject.tag == "AI Bullet")
		Destroy(gameObject);
	SceneManager.LoadScene ("Too Bad");
}

}

If you don’t use the curly braces ( the {'s and }'s) to form a code block, then the if statement will only work on the next immediate statement (Destroy(gameObject)).

This means that you are loading a scene whenever your player enters any trigger at all, not just a bullet. Place the statements you want to execute based on the if condition in curly braces, like:

 void OnTriggerEnter(Collider other) {
     if (other.gameObject.tag == "AI Bullet")
     {
         Destroy(gameObject);
         SceneManager.LoadScene ("Too Bad");
     }
 }

what bobisgod said. it is the equivalent of writing:
if (other.gameObject.tag == “AI Bullet”)
Destroy(gameObject);
if (other.gameObject.tag == “AI Bullet”)
SceneManager.LoadScene (“Too Bad”);

only more efficient