Hi! I am trying to create a button that loads my game. When trying to use Scene Management’s SceneManager.LoadScene, it says that there isn’t definition for it. I looked up and people suggest using application.loadlevel, but it then says it is obsolete, and tells me to use SceneManagement. What should I do? Here’s the code using SceneManager.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SceneManager : MonoBehaviour {
public void PlayBtn(string game)
{
SceneManager.LoadScene(game);
}
}
This is because you have named your own class SceneManager, so when you call SceneManager.LoadScene there is ambiguity, does the compiler use your SceneManager? or Unitys? In this case it is clearly trying to use your SceneManager likely due to the simpler resolution of scope.
I advise naming your class something else OR explicity using the fully qualified name.
UnityEngine.SceneManagement.SceneManager.LoadScene();
To get around this in the future you can also use using statements to effectively typedef in C#
eg in your using statements type
using UnitySceneManager = UnityEngine.SceneManagement.SceneManager;
then you can call UnitySceneManager.LoadScene to avoid ambiguity with your own class name.
I have the same problem, but … Here my code
Its still not working with your solution
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ManageScene : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Start");
}
// Update is called once per frame
void Update()
{
}
public void LoadScene(string scenenos){
SceneManager.loadScene(scenenos); }
}