Application.LoadLevel(Application.loadedLevel);
但现在使用SceneManager会有些奇怪。我读过文档但没有。如何获取当前场景并加载它(Unity 5.3f4)?
谢谢!
答案 0 :(得分:21)
使用新的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);
}
}
答案 1 :(得分:0)
使用SceneMamager
加载当前场景的另一种方法是:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
确保脚本中包含SceneManager
。
答案 2 :(得分:-1)
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");**
}
}
答案 3 :(得分:-3)
这是我的C#示例:)我遇到了同样的问题,现在我已经想到了它,你必须记住你的场景必须包含在项目的构建设置中;)
希望这能帮助其他人拥有新的手套)
干杯:)
附:将此脚本添加到检查器中的按钮,然后选择此脚本和此函数的名称:)
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);
}
}