I trying to end a level but i cant find a script to use. What script should i use to end the level when the player gets to a certain point?
Assuming the player represents a physical in-world `RigidBody` and that it has the tag Player set, you can detect when it enters a trigger and then load your end level scene. Add the following code to a script attached to the trigger (`Collider`) object:
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.CompareTag("Player"))
{
Application.LoadLevel("EndLevel");
}
}
More information here:
http://unity3d.com/support/documentation/Manual/Physics.html http://unity3d.com/support/documentation/ScriptReference/Collider.html http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html
dont forget to check “on trigger” button on the trigger
*if(transform.position = Bector)
{
Application.LoadLevel("nextlevel");
}
var Bector : Vector3;
But make sure you put the exact name of the level and add it to the build settings.
var levelToLoad: int;
function Start(){ levelToLoad = Application.loadedLevel+1; }
function OnTriggerEnter(collider : Collider) {
if(collider.gameObject.tag == "Player"){ Debug.Log("Player collided");
Application.LoadLevel(levelToLoad);
}
}
the best one is
var scene: string;
funvtion OnTriggerEntr{
application.LoadLevel(scene);
}