Good day to all. There was a problem: I made buttons on two scenes so that you can move between them . They worked and I forgot about them . But then I climbed somewhere and everything flew to hell.

The using UnityEngine.SceneManagement used, and the SceneManager.LoadScene("...") writes "The Scene manager does not contain a definition for Load ." I write to SceneManager , put a SceneManager stop and there’s nothing on L at all. Although before that everything worked.

I Don'tDestroyOnLoad(gameobject) somewhere in the teams Don'tDestroyOnLoad(gameobject) . MB it somehow spoiled it. In general, I do not know, I almost did the first project, and here it is ... Tell me who can.

An interesting point : if I create a new project and try to write SceneManager.LoadScene("...") , then everything works, and if I transfer the script from the "problem" project, then the same problem manifests itself.

Script code:

 using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class quality: MonoBehaviour { void OnMouseDown() { switch (gameObject.name) { case "Bad": QualitySettings.currentLevel = QualityLevel.Fastest; break; case "Norm": QualitySettings.currentLevel = QualityLevel.Simple; break; case "Good": QualitySettings.currentLevel = QualityLevel.Fantastic; break; case "Back": SceneManager.LoadScene("1ая игра норм"); break; } } } 
  • Show your code then ...... what version of Unity is used? What is IDE? Writes any errors in the console when you click to save the script with SceneManager.LoadScene ? Comp, unity rebooted? ... maybe it's in the encoding or that instead of an English letter, a Russian (or some other) started somewhere and try to rewrite the script / problem area - Alexey Shimansky
  • Version 5.4.4p2 Personal, IDE -Mono, Error: "SceneManager" does not contain a definition for "LoadScene". The computer rebooted. There are no Russian letters. - Alexander
  • using UnityEngine;using System.Collections; using UnityEngine.SceneManagement; public class quality : MonoBehaviour { void OnMouseDown () {switch (gameObject.name) { case "Bad":QualitySettings.currentLevel = QualityLevel.Fastest; break; case "Norm":QualitySettings.currentLevel=QualityLevel.Simple; break; case"Good":QualitySettings.currentLevel= QualityLevel.Fantastic; break; case"Back":SceneManager.LoadScene("1ая игра норм");break;}}} using UnityEngine;using System.Collections; using UnityEngine.SceneManagement; public class quality : MonoBehaviour { void OnMouseDown () {switch (gameObject.name) { case "Bad":QualitySettings.currentLevel = QualityLevel.Fastest; break; case "Norm":QualitySettings.currentLevel=QualityLevel.Simple; break; case"Good":QualitySettings.currentLevel= QualityLevel.Fantastic; break; case"Back":SceneManager.LoadScene("1ая игра норм");break;}}} - Alexander
  • Well, if in the new project this code is written from scratch with pens and copied into the current one, then what will happen? - Alexey Shimansky
  • only this idea has been visited, now we will try. - Alexander

2 answers 2

You may have created a script called SceneManager. Then we try to look for unity in your script, where, of course, there is no such function. In the picture below, I created a script with the same name in one project and immediately got 3 errors. The problem can be solved in two ways:

  1. faster - rename your script. (It is necessary to rename both in the code and the name in the unit.)
  2. if for some reason you want to use the name SceneManager, you will need to specify in each case that you want to use the SceneManager class not yours, but from the unity library. For example: UnityEngine.SceneManagement.SceneManager.LoadScene ("level1");

    Mistakes when matching names

    Did you move scenes to other folders? I was so because of the fact that the scene was thrown into another folder. After the new one added it to build setings, everything worked.