Hi, so I’ve been working on a game project and I need to get a script that changes the level when the player that is controlled by the standard third person controller. now be prepared as I Know very little about javascript and i’m still trying to learn. heres what I have so far that doesn’t work
var endlevel = false;
var player : Rigidbody;
function Update () {
if.(Collision.player)
set var endlevel = true;
}
Attach a collider to your “End of Level Trigger” object.
Tick the “Is Trigger” option for the collider.
Attach a custom script like the following.
Assets/EndOfLevelTrigger.js
#pragma strict
// Specify name of next level using inspector!
var nextLevelName : String;
function OnTriggerEnter(other : Collider) {
if (other.CompareTag('Player')) {
// Player hit "End of Level Trigger" object!!!
Application.LoadLevel(nextLevelName);
}
}
Please use codetags : [co.de] your code [/co.de] without the dots.
There is a function for the CharacterController called OnControllerCollisionHit, for rigidbodies OnCollisionEnter and some other similar ones
function OnControllerColliderHit ( other : ControllerColliderHit )
{
if ( other.gameObject.tag == "yourTag")
{
Application.LoadLevel( 0 ); // or any other level index, if it's always the next one just put Application.loadedLevel +1 as parameter
}
}