Unity 5.3如何加载当前级别?
在Unity 5.3之前,我能做到
Application.LoadLevel(Application.loadedLevel);
但现在使用SceneManager会有些奇怪。 我读过文档但没有。 如何获取当前场景并加载它(Unity 5.3f4)?
谢谢!
使用新的SceneManager并确保包含名称空间UnityEngine.SceneManagement
using UnityEngine.SceneManagement; public class Example { public void ReloadCurrentScene() { // get the current scene name string sceneName = SceneManager.GetActiveScene().name; // load the same scene SceneManager.LoadScene(sceneName,LoadSceneMode.Single); } }
using UnityEngine; using UnityEngine.UI; using System; using System.Collections; **using UnityEngine.SceneManagement;** public class UIManager : MonoBehaviour{ public void OnRoomJoin(BaseEvent e) { // Remove SFS2X listners and re-enable interface before moving to the main game scene //Reset(); // Goto the main game scene **SceneManager.LoadScene(1);** // **SceneManager.LoadScene("main");** } }
这是我的C#示例:)我遇到了同样的问题,现在我已经想到了它,你必须记住你的场景必须包含在项目的构建设置中;)希望这将有助于其他人在其中使用新的内容)干杯:)
PS将此脚本添加到检查器中的按钮,然后选择您的脚本和此function的名称:)
上述就是C#学习教程:Unity 5.3如何加载当前级别?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class start_new_game : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame public void Update () { } public void OnMouseDown() { SceneManager.LoadScene(0); } }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/949202.html