I’m working on a simple platforming game, and I have it trigger the next level when your character hits the final platform. I was wondering if there is some way to make it so instead of using Application.LoadLevel (2) or whatever level it might be I could just make it load the next one? It would save me a lot of time because I could just make a single prefab platform with the script instead of having to go in and edit the script for every level.
Finally after 4 hours of wasted time…I tried using this and it worked! Yes, you have to create another level and build it. FILE / BUILD SETTINGS etc. This works!!! change the last line to this:
public class Remover : MonoBehaviour
{
public GameObject splash;
void OnTriggerEnter2D(Collider2D col)
{
// If the player hits the trigger…
if(col.gameObject.tag == “Player”)
{
// … stop the camera tracking the player
GameObject.FindGameObjectWithTag(“MainCamera”).GetComponent().enabled = false;
// … stop the Health Bar following the player
if(GameObject.FindGameObjectWithTag(“HealthBar”).activeSelf)
{
GameObject.FindGameObjectWithTag(“HealthBar”).SetActive(false);
}
// … instantiate the splash where the player falls in.
Instantiate(splash, col.transform.position, transform.rotation);
// … destroy the player.
Destroy (col.gameObject);
// … reload the level.
StartCoroutine(“ReloadGame”);
}
else
{
// … instantiate the splash where the enemy falls in.
Instantiate(splash, col.transform.position, transform.rotation);
// Destroy the enemy.
Destroy (col.gameObject);
}
}
IEnumerator ReloadGame()
{
// … pause briefly
yield return new WaitForSeconds(2);
// … and then reload the level. Application.LoadLevel (Application.loadedLevel);