Reputation:
I am a complete beginner in Unity. I was following a YouTube video to learn.
In the video UnityEngine.SceneManagement
was imported then the instructor changed the scene by using SceneManager.LoadScene(scenename);
When I did that, it showed an error. How can I fix that? I am currently using Unity 5.0.
Mainmenu.cs
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class mainmenu : MonoBehaviour {
public GameObject levelButtonPrefab;
public GameObject levelButtonContainer;
private void Start(){
Sprite[] thumbnails = Resources.LoadAll<Sprite> ("Levels");
foreach (Sprite thumbnail in thumbnails) {
GameObject container = Instantiate(levelButtonPrefab)as GameObject;
container.GetComponent<Image>().sprite = thumbnail;
container.transform.SetParent(levelButtonContainer.transform,false);
string scene = thumbnail.name;
container.GetComponent<Button>().onClick.AddListener(()=>loadlevel(thumbnail.name));
}
}
private void loadlevel(string scene){
Debug.Log("1");
}
}
Here is the error I am getting:
Assets/script/mainmenu.cs(4,19): error CS0234: The type or namespace name SceneManagement does not exist in the namespace UnityEngine. Are you missing an assembly reference?
Upvotes: 1
Views: 6223
Reputation: 12258
The UnityEngine.SceneManagement
namespace was introduced in the release of Unity 5.3 (Dec. 2015), as the relevant update notes are the first to mention the deprecation of previous scene management implementations:
Deprecated: EditorApplication class [...] and Application class [...] APIs. They all redirect to equivalent APIs on EditorSceneManager or SceneManager but it is recommended to start using the new APIs instead.
To make use of classes within this namespace such as SceneManager
, you will need to update to the latest version of Unity (or at least version 5.3).
Upvotes: 2