Warining by Application.loadedlevel
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using System.Collections;
public class LevelLoad : MonoBehaviour
{
public string levelName;
public void OnMouseDown() {
// Application.LoadLevel (levelName); old use Scenemanager.LoadScene("")
SceneManager.LoadScene (levelName);
}
public void OnTriggerEnter (Collider other) {
if (other.tag == "Player") {
int next = Application.loadedLevel;
SceneManager.LoadScene (next +001);
// Application.LoadLevel (levelName);
}
}
}
line 18 gives out a warning.. i tried
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex);but this don't work..
can anyone help to convert Application.loadedLevel; to the new method with SceneManager ??
Why not ins$$anonymous$$d hold a hash of values that correlate to the level name and their indexes?
Then increment next to whatever you need, get the name of the level from the hash, and load the level by name?
Even if the level name changes at any point, there's a single place to change the level name (within the hash) and if the ID changes, same thing.
Answer by Ali-hatem · Mar 21, 2016 at 05:05 PM
void OnTriggerEnter (Collider other) {
if (other.tag == "Player") {
//if the index of the current scene is float number like 001 or 002 use float variable
float next = SceneManager.GetActiveScene ().buildIndex;
SceneManager.LoadScene (next +001);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612072741im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. 0 Answers
TextMesh Pro Warning: The character used for Ellipsis is not available in font asset 2 Answers
MonoDevelop Xamarin Source Analysis warning about float comparison? 2 Answers
Avatar Rig Configuration mis-match,Avatar rig configuration mismatch 1 Answer
The problem with the Instantiate 0 Answers