- Home /
Loading a new level from a previous one.
My classmates and I are making a game where we each make our own levels. I'm just wondering how I would go about doing that (I have a script, but it doesn't seem to be working)? The way I'm doing is is having the player enter a box collider with the load next level script attached to it.
So far, this is the code I have to load the next level.
using UnityEngine;
using System.Collections;
public class LoadLevel : MonoBehaviour {
public string levelToLoad;
// Use this for initialization
void Start () {
}
void LoadNextLevel (Collider col) {
if(col.gameObject.tag == "Player") {
Application.LoadLevel(levelToLoad);
}
}
// Update is called once per frame
void Update () {
}
}
Please let me know if I'm missing anything, or have stuff in the wrong spot.
Answer by $$anonymous$$ · Nov 12, 2014 at 07:08 PM
You just need to call function properly
http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
void OnCollisionEnter (Collider col) {
if(col.gameObject.tag == "Player") {
Application.LoadLevel(levelToLoad);
}
}
Unfortunately, I tried both this, and OnTriggerEnter, and neither have worked. Could it be something different, maybe?
void OnCollisionEnter (Collision col) {
if(col.gameObject.tag == "Player") {
Application.LoadLevel(levelToLoad);
}
}
Use Debug.Log("Collider work"); To know if collision works, if it works the problem is in this line Application.LoadLevel(levelToLoad);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Third person movement similar to Max Payne 1 Answer
Starting out C# help 2 Answers
How To Add PlayerPrefs Scores? 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer