How to load another level when you press "E" on the door.

Hi Everyone, I barely started using Unity and I have no understanding of scripting whatsoever. So i need your help. What i want to do is load another level when the player goes to a door and presses “E”. I’ve already put a box collider on the door but i don’t know the script to load another level. Please Help!!

Put this on your dude. Make sure the door is tagged ‘LevelEnd’ in the editor or it won’t work. Otherwise, load the level however you would normally (look up LoadLevel here or the scripting reference, it’s pretty simple). This will check for the existence of a door within 1 unit in front of the player.

void Update()
{
    if(Input.GetKeyDown(KeyCode.E) && CheckForDoor())
    {
        Application.LoadLevel(whatever the next level is);
    }
}

bool CheckForDoor()
{
    RaycastHit hit;
    if(Physics.Raycast(transform.position, transform.forward, out hit, 1))
    {
        if(hit.transform.tag == "LevelEnd")
        {
            return true;
        }
    }
    return false;
}

Your question is in three parts :

How do I know the player is fulfilling the condition to interact with the door (he must be close enough) : Use a trigger as big as the interaction zone OR check the distance when the player press E

How do I detect that the E key is down ? if( Input.GetKeyDown( KeyCode.E ) ) inside Update. I suppose you already knew, but it doesn’t hurt to have too much info.

How do I load a new level ? With Application.LoadLevel( 0 ) or by its name. Bee careful on webplayer, the level might not be ready to be loaded.