winpoint error

hey

(sry for mistakes in question im german :D) i want a script that when im in a area an press e i get in te next level:

static var doorzone =false;

function OnTriggerEnter(Collider) {

doorzone = true;

 if(Input.GetButtonDown("e")){

Application.LoadLevel(1);

}
}

if i in the area there came no error but it dosent work thanks for help.

OnTriggerEnter() will only be called on first entering a collider zone. This means they must be holding the e key down when entering the zone for this to work. You probably want OnTriggerStay() instead which will be true any time they are inside the trigger zone.

When you aren’t sure if code is getting called or not, you have two options. 1) Start the debugger in Mono develop on the Unity app. Place a breakpoint in the code you want to know if you’re hitting. 2) Much less methodical, but nonetheless I find myself using much more often (lol) is to just put a Debug.Log() print everywhere you think you are getting and where you need to go. Then watch the console window for log printouts. It would have become clear to you that you only get a single print out every time you entered the trigger zone by doing that.

EDIT: Before I get dinged for saying Debug.Log() is less intelligent, I’ll clarify that I mean it’s a less logical way. It’s very useful and sometimes the only method that makes sense, especially when the breakpoint will mess up your timing. Forget it, I changed it from intelligent to logical. No, methodical, that’s it. If anyone has a better term, I’ll use it.