Basically im looking for a way to be able to run into a collider and load the next level that I say. I thought of trying to make an empty object and make a collider and use tags with a script. But I could not get it to work. Is there a script or video tutorial/steps somewhere on how to make a teleporter to a new scene.
Use this line of code on the collision of whatever object you want to use as the teleporter.
Application.LoadLevel(LevelID);
LevelID is the id of the level that is set in your build preferences. This is an integer value. To set up different levels with IDs go to File->Build Settings and then drag in the levels you want. Make sure the check box to the left is checked and use the number on the very right of your desired level in place of LevelID.
Can start with something pretty simple along the lines of:
var destinationLevel : int = 0;
function OnTriggerEnter(obstacle : Collider) {
Application.LoadLevel(destinationLevel);
}
And then add to it.
I use something like this that plays a teleport sound, disables the GUI, etc.
Ok so Im gonna post this: VIDEO : on what im trying to do. I added my level code into my moving script… see if you can spot what im doing wrong… this is the
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitprefab:Transform;
static var dead = false;
var tumbleSpeed = 800;
var decreaseTime = 0.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0, 4, 0);
gameObject.Find("Main Camera").transform.position = Vector3(47,1,-37);
dead = false;
}
if(gotHit)
{
if(tumbleSpeed < 1)
{
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
}
}
//function OnControllerColliderHit(hit:ControllerColliderHit)
function OnTriggerEnter( hit : Collider )
{
if(hit.gameObject.tag == "NextL2")
{
Application.LoadLevel(2);
}
if(hit.gameObject.tag == "fallout")
{
dead = true;
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "enimyProjectile")
{
gotHit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitprefab, transform.Find("SpawnPoint").transform.position, Quaternion.identity);
bullit.tag = "wormProjectile";
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
@script RequireComponent(CharacterController)
Instead of checking against “hit.gameObject.tag” you need to check against “hit.gameObject.name”. Your video shows that the name is NextL2 and the tag is nextLevel. Tag and name are not one in the same. (wasn’t trying to rhyme, but it has a nice ring to it)