- Home /
Can not get Level to Load using level collider
Hi,
I am trying to use a collider to initiate a level change, but I am having no luck and I don't know why. Here is my script:
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag=="NextLevel"){
Application.LoadLevel("level2");
}
}
Also, if you can help me, I wanted to initiate new levels with some sort of delay, and came up with this, and wondered if I could just add part of this script to the collider script.
private var myTimeout:float;
function Start()
{
myTimeout = Time.time+30; // 30 second delay
}
function Update()
{
if(Time.time > myTimeout)
{
Application.LoadLevel("level2");
}
}
Thank you for helping me.
I hate to nitpick, but fixing people's post formatting gets a bit old after a while.
Answer by syclamoth · Apr 18, 2012 at 12:11 AM
For the first part, make sure you have at least one rigibody in the interaction, so that physics gets activated. This kind of thing is like the second-most asked question, so look around this site and I'm sure you'll find a few (hundered) answers to your problem.
As for the second part, the easiest way to do that would be like this:
function DelayedLevelLoad(waitTime : float)
{
yield WaitForSeconds(waitTime);
Application.LoadLevel("level2");
}
Then, just call that function from anywhwere with a number for the amount of time, and you're good!
DelayedLevelLoad(30); // loads the level after 30 seconds
I did everything the right way, I just never added the second level to the build... Sometimes it's the little things.
Your answer
![](https://koobas.hobune.stream/wayback/20220613070442im_/https://answers.unity.com/themes/thub/images/avi.jpg)