///2015/08/22///

//by    xbw///

//环境 unity 4.6.1

有了人物购买系统要是没有人物信息的显示是不是感觉并没有什么卵用呢,这样呢,我决定做一个信息显示的模块。先看一下效果图,

这个图实现了什么呢。就是点击一下角色下方然后弹出信息框。而且人物模型动画移动到了右边,下边先来一段实现代码。

using UnityEngine;
using System.Collections;public class renwuxixinUI : MonoBehaviour {// Use this for initializationpublic Texture2D bai;public Texture2D hei;public Texture2D hong;public Texture2D ming;public Texture2D jing;public Texture2D lan;public Texture2D img;public int shu=-1;public int shu2 = -1;void Start () {}// Update is called once per framevoid Update () {shu = quanju.flag2;shu2 = quanju.flag;}void OnGUI(){if((shu==0||shu2==0)&&quanju.dang){GUI.DrawTexture(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.7f, Screen.height * 0.7f), bai);if (GUI.Button(new Rect(Screen.width * 0.1f + Screen.width * 0.642f, Screen.height * 0.11f, Screen.width * 0.04f, Screen.width * 0.04f), "")){quanju.dang = false; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.right * 5.0f); }GUI.DrawTexture(new Rect(Screen.width * 0.1f + Screen.width * 0.63f, Screen.height * 0.08f, Screen.width * 0.065f, Screen.width * 0.065f), img);}if ((shu == 5 || shu2 == 5) && quanju.dang){GUI.DrawTexture(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.7f, Screen.height * 0.7f), hei);if (GUI.Button(new Rect(Screen.width * 0.1f + Screen.width * 0.642f, Screen.height * 0.11f, Screen.width * 0.04f, Screen.width * 0.04f), "")){quanju.dang = false; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.right * 5.0f);}GUI.DrawTexture(new Rect(Screen.width * 0.1f + Screen.width * 0.63f, Screen.height * 0.08f, Screen.width * 0.065f, Screen.width * 0.065f), img);}if ((shu == 4 || shu2 == 4) && quanju.dang){GUI.DrawTexture(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.7f, Screen.height * 0.7f), hong);if (GUI.Button(new Rect(Screen.width * 0.1f + Screen.width * 0.642f, Screen.height * 0.11f, Screen.width * 0.04f, Screen.width * 0.04f), "")){quanju.dang = false; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.right * 5.0f);}GUI.DrawTexture(new Rect(Screen.width * 0.1f + Screen.width * 0.63f, Screen.height * 0.08f, Screen.width * 0.065f, Screen.width * 0.065f), img);}if ((shu == 3 || shu2 == 3) && quanju.dang){GUI.DrawTexture(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.7f, Screen.height * 0.7f), ming);if (GUI.Button(new Rect(Screen.width * 0.1f + Screen.width * 0.642f, Screen.height * 0.11f, Screen.width * 0.04f, Screen.width * 0.04f), "")){quanju.dang = false; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.right * 5.0f);}GUI.DrawTexture(new Rect(Screen.width * 0.1f + Screen.width * 0.63f, Screen.height * 0.08f, Screen.width * 0.065f, Screen.width * 0.065f), img);}if ((shu == 2 || shu2 ==2) && quanju.dang){GUI.DrawTexture(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.7f, Screen.height * 0.7f), jing);if (GUI.Button(new Rect(Screen.width * 0.1f + Screen.width * 0.642f, Screen.height * 0.11f, Screen.width * 0.04f, Screen.width * 0.04f), "")){quanju.dang = false; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.right * 5.0f);}GUI.DrawTexture(new Rect(Screen.width * 0.1f + Screen.width * 0.63f, Screen.height * 0.08f, Screen.width * 0.065f, Screen.width * 0.065f), img);}if ((shu == 1 || shu2 == 1) && quanju.dang){GUI.DrawTexture(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.7f, Screen.height * 0.7f), lan);if (GUI.Button(new Rect(Screen.width * 0.1f + Screen.width * 0.642f, Screen.height * 0.11f, Screen.width * 0.04f, Screen.width * 0.04f), "")){quanju.dang = false; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.right * 5.0f);}GUI.DrawTexture(new Rect(Screen.width * 0.1f + Screen.width * 0.63f, Screen.height * 0.08f, Screen.width * 0.065f, Screen.width * 0.065f), img);}}
}

实现并不困难,可是要想一点bug都没有非常费劲,调试了不知道几十遍,没一点都要考虑到。由于我们的信息显示了人物已购买跟人物未购买,所以必须调用数据库。究竟有没有购买。上边一段代买仅仅是显示信息UI的。至于那些推断条件。我们用在了别处,看到都是用了全局变量了吧,在之前的文章中。characterselect.cs脚本中,我们有这样一段代码;

 if (index == 0){if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "太空小白" + "\n" + "5000$" + "\n" + "已内购")){ quanju.dang = true; quanju.flag = 0; quanju.flag2 = 0; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f); }               }if (index == 5){if (quanju.renwu5 == 1){if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "忍者小黑" + "\n" + "50000$" + "\n" + "已购买")){quanju.dang = true; quanju.flag = 5; quanju.flag2 = 5; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}else{if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "忍者小黑" + "\n" + "50000$" + "\n" + "未购买")){quanju.dang = true; quanju.flag2 = 5; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}}if (index == 4){if (quanju.renwu4 == 1){if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "功夫小红" + "\n" + "40000$" + "\n" + "已购买")){quanju.dang = true; quanju.flag = 4; quanju.flag2 = 4; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}else{if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "功夫小红" + "\n" + "40000$" + "\n" + "未购买")){quanju.dang = true; quanju.flag2 = 4; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}}if (index == 3){if (quanju.renwu3 == 1){if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "明明" + "\n" + "30000$" + "\n" + "已购买")){quanju.dang = true; quanju.flag = 3; quanju.flag2 = 3; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}else{if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "明明" + "\n" + "30000$" + "\n" + "未购买")){quanju.dang = true; quanju.flag2 = 3; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}}if (index == 2){if (quanju.renwu2 == 1){if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "静静" + "\n" + "20000$" + "\n" + "已购买")){quanju.dang = true; quanju.flag = 2; quanju.flag2 = 2; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}else{if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "静静" + "\n" + "20000$" + "\n" + "未购买")){quanju.dang = true; quanju.flag2 = 2; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}}if (index == 1){if (quanju.renwu1 == 1){if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "刑警小蓝" + "\n" + "10000$" + "\n" + "已购买")){quanju.dang = true; quanju.flag = 1; quanju.flag2 = 1; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}else{if (GUI.Button(new Rect(Screen.width * 0.42f, Screen.height * 0.6f, Screen.width * 0.15f, Screen.height * 0.3f), "刑警小蓝" + "\n" + "10000$" + "\n" + "未购买")){quanju.dang = true; quanju.flag2 = 1; GameObject.FindGameObjectWithTag("Player").transform.Translate(Vector3.left * 5.0f);}}}

按下button的几个开关变量,还有角色的移动,非常清楚了吧,嘿嘿,还不错吧

就这样了,有不懂的地方或者实现有错误的请留言呢,我会一一回复的,希望大家互相学习,共同进步

Unity3D开发——LeRunning的人物角色信息的显示相关推荐

  1. unity android eclipse,[转]Android笔记:Eclipse嵌入Unity3D开发的3D场景

    1.Unity3D开发程序员开发好场景后,打包apk包,将此apk包发给android开发人员 2.android开发人员将得到的apk包后缀名改为.zip(即重命名将.apk改为.zip) 3.解压 ...

  2. 一、创建Assetbundle 在unity3d开发的游戏中,无论模型,音频,还是图片等,我们都做成Prefab,然后打包成Assetbundle,方便我们后面的使用,来达到资源的更新。

    一.创建Assetbundle 在unity3d开发的游戏中,无论模型,音频,还是图片等,我们都做成Prefab,然后打包成Assetbundle,方便我们后面的使用,来达到资源的更新. 一个Asse ...

  3. Unity3d开发IOS游戏 基础

    Unity3d开发IOS游戏 基础 @阿龙 -  649998群 1.先说明两个问题,我在WIN7下面的U3D里面,用了雅黑字体,但是导出为ios后,字体就看不见了,这是为什么呢?这是需要在MAC下找 ...

  4. Unity3d开发跳一跳-郑洪智-专题视频课程

    Unity3d开发跳一跳-2883人已学习 课程介绍         使用Unity2017.3开发"跳一跳"小游戏的教程. 课程收益     用Unity3d 2017.3实现微 ...

  5. Unity3D开发的赛车单机小游戏详细介绍(附有游戏下载链接)

    博主使用Unity3D开发的赛车单机游戏详解(文末附游戏下载地址,由于时间过长,游戏源码已无法找到,请谅解) 设计开始于想象. 空中跑道,深山小亭,隐藏在森林中的跑车- 一切等着你去发现,去体验- 我 ...

  6. unity3d开发鼠标打飞碟游戏(Hit UFO)

    这次我们用Unity3d开发一个简单的打飞碟游戏 游戏简介 游戏有3个回合,每个回合会发射n中颜色的飞碟,击中飞碟会得到相应的分数,其中,击中黄色飞碟得1分,击中蓝色飞碟得2分,红色飞碟4分,击不中不 ...

  7. Unity3D 开发 HTC Vive安装及如何连接电脑详细教程(全程图解)

    HTC Vive安装及如何连接电脑详细教程: 在市场上的诸多VR产品当中,htc Vive无疑是体验最佳的设备之一,不过在享受高端硬件带来美妙沉浸感之前,必须要经过一段略微复杂的"手续&qu ...

  8. unity3d开发实战《啪啪三国》技术详解

    http://www.unitymanual.com/thread-13031-1-1.html      去年11月,上海火溶网络CEO王伟峰以其第一款3d手游产品<啪啪三国>为例,着重 ...

  9. unity3d开发实战《啪啪三国》技术详解!

    unity3d开发实战<啪啪三国>技术详解!  去年11月,上海火溶网络CEO王伟峰以其第一款3d手游产品<啪啪三国>为例,着重讲解了unity3D手机网游开发的经验,其中涉及 ...

最新文章

  1. 解决Mysql复制Relay log read failure 的问题
  2. 小时候糖吃多了,长大后记性会变差| Nature子刊最新研究
  3. 1.20 Java8新特性:Effectively final
  4. size_t是什么数据类型?为什么要用size_t替代int、unsigned int、unsigned long、unsigned long long
  5. 【LeetCode笔记】406. 根据身高重建队列(Java、偏数学)
  6. eclispe Springboot项目修改html,jsp 页面不能及时刷新
  7. 线性代数:矩阵及其运算
  8. 音频测试方法(tiny)
  9. aria2使用rpc下载百度云
  10. MySQL5.6 community从下载到安装
  11. html标签logo怎么去掉,镜片上的logo怎么去掉
  12. halcon测试篇:求两条线之间的交点
  13. 华为交换机配置ntp服务时间 自动同步不成功unsynchronized
  14. NanoPi R2S 专用软件源
  15. php常见面试题总结
  16. 1.C语言的特点和学习目标
  17. HDMI以及HDCP之间的关系介绍
  18. [网友问答1]STM32驱动PCF8591模块,实现AD/DA转换
  19. Oracle 创建用户详解(create user)
  20. 幼儿园小朋友可以教创业者的事

热门文章

  1. Generator-ing Values
  2. 2109春第一次课程设计实验报告
  3. 雷林鹏分享:jQuery EasyUI 数据网格 - 创建页脚摘要
  4. bootstrap简单登录界面
  5. bzoj2154 Crash的数字表格
  6. Qt pro使用sql之类的需要添加的模块
  7. javascript常用代码大全
  8. NES模拟器开发-CPU笔记
  9. C++类构造函数中的成员初始化
  10. 有向连通图增加多少边构成强联通(hdu3836,poj1236)