Unity3D:按钮实现场景的跳转

来源:互联网 发布:淘宝店铺源代码生成器 编辑:程序博客网 时间:2024/06/07 01:21
这一示例使用一个按钮以及脚本演示如何跳转场景(scene)

软件版本:5.3.2.f1

1.将场景加入Buildsetting

打开File----Build Setting,打开场景,点击Add OpenScenes将当前几个场景加入进去

Unity3D:按钮实现场景的跳转


2.在开始界面场景添加一系列Button

GameObject ---- UI-----Button

Unity3D:按钮实现场景的跳转


3.编写按钮的脚本






ButtonNewgame.cs:




using UnityEngine;
using System.Collections;
using UnityEngine.UI;
usingUnityEngine.SceneManagement;

public class ButtonNewgame : MonoBehaviour {

// Use this for initialization
void Start () {
}
   void Awake()
   {
       Button button =gameObject.GetComponent
      button.onClick.AddListener(btClick);//添加监听器用于监听按键事件,并回调函数
   }
    // Update is called onceper frame
    void Update () {
}
    void btClick()
   {
       print("ButtonClick");
      SceneManager.LoadScene(1);//跳转到指定的Level,也就是第一步中的右侧标号
   }
}



4.将按钮脚本拖入指定按钮




0 0
原创粉丝点击