我是Unity的初学者。我正在关注YouTube视频进行学习。
在导入的视频UnityEngine.SceneManagement
中,教师使用SceneManager.LoadScene(scenename);
当我这样做时,它显示错误。我该如何解决这个问题? 我目前正在使用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");
}
}
以下是我遇到的错误:
Assets / script / mainmenu.cs(4,19):错误CS0234:类型或命名空间 名称SceneManagement在命名空间UnityEngine中不存在。 你错过了装配参考吗?
答案 0 :(得分:2)
在Unity 5.3(2015年12月)的版本中引入了UnityEngine.SceneManagement
命名空间,因为relevant update notes是第一个提及以前场景管理实现的弃用:
不推荐使用:EditorApplication类[...]和Application类[...] API。它们全部重定向到等效的API EditorSceneManager或SceneManager但建议启动 改为使用新的API。
要使用此命名空间中的类(例如SceneManager
),您需要更新到最新版本的Unity(或至少版本5.3)。