UnityEngine 命名空间中没有 "UnityEngine.SceneManagement"?
No "UnityEngine.SceneManagement" in UnityEngine namespace?
我是 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): error CS0234: The type or namespace
name SceneManagement does not exist in the namespace UnityEngine.
Are you missing an assembly reference?
Unity 5.3(2015 年 12 月)发布时引入了 UnityEngine.SceneManagement
命名空间,因为 relevant update notes 是第一个提到弃用以前场景管理实现的人:
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.
要在 SceneManager
等命名空间中使用 类,您需要更新到最新版本的 Unity(或至少版本 5.3)。
我是 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): error CS0234: The type or namespace name SceneManagement does not exist in the namespace UnityEngine. Are you missing an assembly reference?
Unity 5.3(2015 年 12 月)发布时引入了 UnityEngine.SceneManagement
命名空间,因为 relevant update notes 是第一个提到弃用以前场景管理实现的人:
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.
要在 SceneManager
等命名空间中使用 类,您需要更新到最新版本的 Unity(或至少版本 5.3)。