door script help?

hi there i was wondering if anyone could create or find me script to load another scene?

basically its to load a building interior(just another scene) from outside and obviously be able to exit(load my exterior scene) any help would be appreciated,thanks

hey make a trigger on the door and when it collides with your Hero/player then use something like this Unity - Scripting API: Application.LoadLevel :slight_smile:

hi thanks for the help but i havent used triggers before what do i need to do in unity?

hehe you need to make a javascript(unityscript) and make something like this :slight_smile: im no expert and its made from my head

function OnTriggerEnter(Player : Collision)
{
	if(Player.gameObject.tag == ("Player"))
	{
		Application.LoadLevel(2);
	}
}

thanks although when i collide with the object with the script attached nothing happens i have both levels in the build and yet no luck so far
p.s i have edited the script to load my levels of course and made sure that the tags are the same?

you need to make sure that the (2) is the samme as your level you can just change the 2 to the name of your level :slight_smile:

ps and the (Player : Collision) i think needs to be (Player : Collider) :slight_smile: like i said im no expert :slight_smile: hope it helps :wink:

Also make sure that the moving object(player) has a rigid body attached to it. And some sort of collision volume too.

yup, they’re all right, you must use void OnTriggerEnter(other : Collider){}, check the name of the gameObject that has the collider other on it, so it’ll be the one you want (a.k.a. your player controller or whatever) then you have to make sure the collider placed in the opened space of the door has checked the “Is Trigger” option in the Inspector tab, and make sure you have a rigidbody attached to your player. and if you have many doors, you can add a switch case based on the door collider name or smt like this, to make sure you load the level you need.

for example you have 2 different doors which load 2 diff levels. let’s say we name the gameobjects to which we attach the colliders (trigger ones) door1 and door2… so door1 loads level 1 and door 2 loads level 2, and we’re in the level 0. make all the trigger colliders gameobjects named based on the level they need to load, and in your OnTriggerEnter() funcion do something like this:

if(other.name == "player"){
	switch (gameObject.name){
		case "door1":
			Application.LoadLevel(1);
		break;
		case"door2":
			Application.LoadLevel(2);
		break;
		//so on
		default:
			//do nothing
		break;
	}
}