您的位置:首页 > 移动开发 > Unity3D

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

2017-06-06 19:43 405 查看

讲解上一篇文章(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 = memberSpr
4000
ite;
}
//显示开始界面,返回按钮点击时调用
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欢迎撩

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d c#