基于Unity3D的2d拾宝游戏(七)

来源:互联网 发布:pdf.js 跨域加载文件 编辑:程序博客网 时间:2024/06/06 08:24

讲解上一篇文章(http://blog.csdn.net/qq_29859497/article/details/72886710)中提及的UI控制实现(C#)


UI控制类(所有按钮点击时都将调用此类):


using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class UIController : MonoBehaviour {    public Button begin;    public Button introduce;    public Button member;    public Button back;    public Image image;    public Sprite introSprite;    public Sprite memberSprite;    //返回开始界面,返回首页按钮点击时调用    public void ReturnStartPage() {        Application.LoadLevel(0);    }    //开始游戏,开始游戏及再玩一次按钮点击时调用    public void BeginGame() {        Application.LoadLevel(1);//点击开始按钮,进入第一关    }    //显示游戏介绍,游戏介绍按钮点击时调用    public void Introduce(bool show) {        SetActiveState(show);        image.GetComponent<Image>().sprite = introSprite;    }    //显示小组成员,小组成员按钮点击时调用    public void Member(bool show) {        SetActiveState(show);        image.GetComponent<Image>().sprite = memberSprite;    }    //显示开始界面,返回按钮点击时调用    public void Back(bool show) {        SetActiveState(show);    }    //设置界面按钮活动状态    void SetActiveState(bool show) {        begin.gameObject.SetActive(show);        introduce.gameObject.SetActive(show);        member.gameObject.SetActive(show);        back.gameObject.SetActive(!show);        image.gameObject.SetActive(!show);    }}

待续。


附:相关代码编写伙伴BLOG:XiaoMingAudioMiao欢迎撩

原创粉丝点击