1,我已经创建好两个场景,放到Scene目录下
2,然后分别运行其场景,在运行的过程中,点击“File”->“Build Setting”;
如图所示,点击“Add Current”,场景就会自动加进去了
3,给LoginSence中的button加一个点击事件,代码如下
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
public class LoginMgr : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log("game is start");
var LoginBtn = gameObject.GetComponent<Button>();
if (LoginBtn.name == "Btn_Login")
{
LoginBtn.ButtonClickEvent = LoginMethod;
}
}
public void LoginMethod(BaseEventData eventData)
{
Debug.Log("开始跳转场景");
Application.LoadLevelAsync("SelectLevelSence");
Debug.LogWarning("我成功啦");
}
void Awake() {
Debug.Log(" this is LoginMgr's Awake()");
}
// Update is called once per frame
void Update () {
Debug.Log(" this is LoginMgr's Update()");
}
}
Application.LoadLevelAsync("SelectLevelSence");和Application.LoadLevelAsync(1);这两种方法都可以.。一个是加载名“SelectLevelSence”的关卡,一个是加载索引为1的关卡
4,运行游戏,点击按钮,就会进入下一个场景了