Unity5 新api:Scenemanager场景切换

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");
}
}
}

 

posted @ 2016-06-17 23:46  Haleclipse  阅读(926)  评论(0编辑  收藏  举报