SceneManager.LoadScene的使用方法

来源:互联网 发布:unturned汉化mac 编辑:程序博客网 时间:2024/06/07 19:31
using UnityEngine;

using System.Collections;

//SceneManager.LoadScene方法所在的类必须要添加后才可使用

using UnityEngine.SceneManagement;
[AddComponentMenu("MyGame/TitleSceen")]


public class TitleSceen : MonoBehaviour {


void OnGUI(){
//文字大小
GUI.skin.label.fontSize = 48;
//UI中心对齐    TextAnchor.LowerCenter指的是在Label矩形框内的位置
GUI.skin.label.alignment = TextAnchor.LowerCenter;

//显示标题
GUI.Label(new Rect(0,30,Screen.width,150),"太空大战");
//开始游戏按钮
if (GUI.Button (new Rect (Screen.width * 0.5f - 100, Screen.height * 0.7f, 200, 30), "开始游戏")) {
//开始读取下一关LoadLevel在新版本中被废除了

//Application.LoadLevel(1);

//在5.0版unity中应用SceneManager.LoadScene来取代

SceneManager.LoadScene("SpaceWar");
}
}

}


SceneManager.LoadScene

public static void LoadScene(int sceneBuildIndexSceneManagement.LoadSceneMode mode = LoadSceneMode.Single);

public static void LoadScene(string sceneNameSceneManagement.LoadSceneMode mode = LoadSceneMode.Single);

Parameters

sceneNameName of the scene to load.sceneBuildIndexIndex of the scene in the Build Settings to load.modeAllows you to specify whether or not to load the scene additively. See LoadSceneMode for more information about the options.

Description

Loads the scene by its name or index in Build Settings.

The given sceneName can either be the last part of the path, without .unity extension or the full path still without the .unity extension. The path has to be exactly as shown in the Build Settings Window. If only the scene name is given this will load the first scene in the list that matches. If you have multiple scenes with same name but different paths, you should use the full path.



2 0
原创粉丝点击