Door opens next level

hello. I have been trying to write a script that makes it so if your standing in front of the door and press space, it will take you to the next level or scene. I had a script that did so except it didn’t matter whether or not you were next to the door.
can someone please help?

You will want to use Physics.RayCast and load the level when the raycast hits the door.

var hitDistance : float = 4;

function Update() {
    if(Input.GetKeyDown("space") {
        var hit : RaycastHit;
             
        if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit, hitDistance)) {
            if(hit.transform.gameObject.name == "NextLevelDoor") {
                Application.LoadLevel(Application.loadedLevel+1) // Loads next level
            }
	}
    }
}

alright, so I just add a raycast to the character or what? I’m still pretty new to everything

If you add the exact script I provided to your player (or camera if it is a FPS), change the name from “NextLevelDoor” to the name of your door, and depending on how you organized your game, picked the next level instead of Application.loadedLevel+1, it should work.

AWESOME! works great thanks!

Triggers are pretty handy as well. Ultimately, reading the docs and leaning basic programming is the best thing you can do.