Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour
{
public int levelVar;
public string sceneName;
private void Start()
{
Debug.Log("levelVar "+levelVar.ToString());
//Debug.Log("loadedLevel "+Application.loadedLevel);
Scene scene = SceneManager.GetActiveScene();
Debug.Log("La scène active est '" + scene.name + "'.");
sceneName = scene.name;
}
public void NextLevelButton()
{
while(sceneName != "level"+levelVar.ToString());
{
Debug.Log("valeur niveau est incorrecte -> "+levelVar);
levelVar++;
}
Debug.Log("level"+levelVar.ToString());
Application.LoadLevel("level"+levelVar.ToString());
}
}
j'ai testé le script dans ces condition:
il y a 5 scene:
-level1
-level2
-level3
-level4
-level5
(j'étais sur la scene "level1" (j'utilise la version 2019.2.14f1 de unity mais je ne sais pas si c'est important))