unity3d 切换场景
2015-07-02 16:29
549 查看
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,运行游戏,点击按钮,就会进入下一个场景了
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,运行游戏,点击按钮,就会进入下一个场景了
相关文章推荐
- Git Community Book 中文版
- unity中如何获取所有子物体的组件
- Unity3D总结:关于射线碰撞
- Unity3D工作中小技巧
- Unity学习 - Masking and clipping textures using shaders in NGUI
- unity3D 根据所在文件夹自动设置一些属性
- 【Unity】UGUI Text文本描线。。
- Unity里面三角面数
- Unity管理Debug.log输出的Log
- Unity3D常用插件下载及使用方法
- Unity导出的Android项目按钮无法点击问题
- Intermediate Unity 3D for iOS: Part 3/3
- UnityShader实例05:Toon(卡通)材质
- [Unity3D]引擎崩溃、异常、警告、BUG与提示总结及解决方法
- Unity学习 - C#委托的介绍(delegate、Action、Func、predicate)
- 【风宇冲】Unity3D教程宝典之两步实现超实用的XML存档
- Unity学习 - C#委托的介绍(delegate、Action、Func、predicate)
- unity多人开发,更新svn后材质丢失(模型贴图全变紫)的问题
- Unity3D游戏开发之从Unity3D项目版本控制说起
- Unity3D实践系列11, 组件的添加和访问