- Home /
Door open/load level java script troubles
var Destination = (0);
private var controller : FirstPersonController;
@script RequireComponent(FirstPersonController)
function Start ()
{
controller = GetComponent (FirstPersonController);
}
function OnControllerColliderHit (hit : ControllerColliderHit) {
if(Input.GetKeyUp("e"))
{ //load level Application.LoadLevel(Destination); }
}
Why does'nt this work?
Answer by YeOldeSnake 1 · Dec 28, 2010 at 02:17 PM
I would use tags with gameobjects instead , and make a trigger in front of the door and use OnTriggerStay instead of colliding cause oncolliderhit is only called for one frame when the hit happens here is some exemplary code , add this to the trigger in front of the door (untested but it should give you the idea)
var Destination ="MyLevel"; function OnTriggerStay (other : Collider) { if(other.gameObject.tag =="Player"){ if(Input.GetKeyUp("e")) Application.LoadLevel(Destination);
}
}
You should also use level names for Application.LoadLevel , it takes away the confusion if you have a lot of levels
Your answer
Follow this Question
Related Questions
Animation Script not working. 1 Answer
Raycasting fail 1 Answer
Script doesn't find other script 0 Answers