当前位置:   article > 正文

SceneManager.LoadScene的使用方法

scenemanager.loadscene
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  sceneBuildIndex SceneManagement.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.



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/122477
推荐阅读
相关标签
  

闽ICP备14008679号