- Home /
Question by
Deel · Aug 11, 2013 at 08:30 PM ·
c#triggerloadlevelboxcollider
Level dont loaded, after enter a Trigger BoxCollider
Hello, i want, that the game loads the next level, when my player enter a Triggerbox. But it doesnt work. When i make a button for load the next level it works? The player has the right tag. I have no idea. The script is attached to the box collider of the levelend.
My code:
using UnityEngine;
using System.Collections;
public class LoadNextLevel : MonoBehaviour {
public string levelName ="";
public string tag = "";
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnTrigerEnter(Collider other)
{
if(other.gameObject.tag == tag)
{
Application.LoadLevel(levelName);
Debug.Log("NextLevel");
}
}
void OnGUI()
{
if(GUI.Button(new Rect(300,300,100,100),"NextLvl"))
{
Application.LoadLevel(levelName);
}
}
}
Comment
Best Answer
Answer by robertbu · Aug 11, 2013 at 08:31 PM
It should be 'OnTriggerEnter()' with two 'g'.
$$anonymous$$hh, always not. The player has a Box Collider which is not Trigger and the levelending a Trigger BoyCollider. Any other ideas?
One of the two bodies must have a rigidbody. If you are using a character controller ins$$anonymous$$d of a rigidbody, you will have to use some other method of triggering your load level.