'SceneManager does not contain definition for LoadScene'
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);
}
}
Have you tried to clean your solution / scripts and rebuild them, or have you tried to close and restart $$anonymous$$onoDevelop?
Answer by HenryStrattonFW · Jan 19, 2017 at 08:33 PM
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.
Answer by swordcat13 · Oct 06, 2020 at 08:47 PM
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); }
}
EDIT: Strike my previous. Your code does have an error, you're using a lower case l in loadScene, it needs to be upper case "LoadScene"
Your answer
Follow this Question
Related Questions
random loss of component variable value 2 Answers
Is true async scene loading possible? 0 Answers
Why is my scene not loading? 2 Answers