LoadLevelAdditive loads too many levels

Hi guys,
So I’m making a short FPS and I use different scenes to display some text /informations. Basically when the player is next to an object and wants to examine it, he hits E which loads another scene on top of my first one with Application.LoadLevelAdditive.
That’s my script (on the player):

void OnTriggerStay (Collider target) {
if (target.tag == “1_tomb”)

			if (Input.GetKeyDown (KeyCode.E)) {
					
					Application.LoadLevelAdditive(1);
			}
	}

The problem is that this script seems to load the second level several times - sometimes up to 5 times (which is problematic as I use some transparency effects on the second level and it’s very visible that several objects are loaded)

So, could somebody explain why this happens and how I can make it so that the level is loaded only ones?

Thanks for the help!

Hi. This is happening because OnTriggerStay gets called whenever something stays inside the trigger. This means for each physics update that happens and you are pressing E while inside the trigger, the scene will be loaded.

You’ll have to add some sanity in here to check if it’s already loading that level. Application.isLoadingLevel

or if it’s already loaded (by looking for it in the scene).