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.



  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值