- Home /
Question by
PERFKNIGHT · Feb 06, 2017 at 01:09 PM ·
scripting problemerrorscene
Universal Level Changer with SceneMnager
I'm trying to create a universal script for changing levels using an instantiated object. This is the code I was trying to use, but apparently, it is obsolete. Is there a method of doing this with the new SceneManager?
using UnityEngine;
using System.Collections;
public class AdvanceLevel : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if (other.tag == "Finish")
{
Application.LoadLevel(Application.loadedLevel + 1);
}
}
}
Comment
Answer by HarshadK · Feb 06, 2017 at 01:48 PM
All you need to do is replace:
Application.LoadLevel(Application.loadedLevel + 1);
with
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex + 1);
For more details read: SceneManager
Your answer
Follow this Question
Related Questions
Failed to unpersist: MonoBehaviour ID and then unity destroys our scene. 3 Answers
Getting an error while trying to get scene name 1 Answer
Cant fetch components from GameObjects stored in an array? 0 Answers
How do I access a variable from a different scene using C#? 3 Answers
Help with loading a scene,Help changing scenes (C~ script) 1 Answer