Unity3D开发——LeRunning的人物角色信息的显示
///////////////////////2015/08/22///////////////
//////////////////////by xbw///////////////////
//////////////////////环境 unity 4.6.1////////
有了人物购买系统要是没有人物信息的显示是不是感觉并没有什么卵用呢,这样呢,我决定做一个信息显示的模块。先看一下效果图,
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
这个图实现了什么呢。就是点击一下角色下方然后弹出信息框。而且人物模型动画移动到了右边,下边先来一段实现代码。
using UnityEngine;
using System.Collections; public class renwuxixinUI : MonoBehaviour { // Use this for initialization
public 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 frame
void 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的人物角色信息的显示的更多相关文章
- Unity3d开发IOS游戏 基础
Unity3d开发IOS游戏 基础 @阿龙 - 649998群 1.先说明两个问题,我在WIN7下面的U3D里面,用了雅黑字体,但是导出为ios后,字体就看不见了,这是为什么呢?这是需要在MAC下找 ...
- unity3d开发实战《啪啪三国》技术详解!
去年11月,上海火溶网络CEO王伟峰以其第一款3d手游产品<啪啪三国>为例,着重讲解了unity3D手机网游开发的经验,其中涉及了团队组成.人员要求.常见的unity3d开发遇到的坑及解 ...
- 跟我从零基础学习Unity3D开发--NGUI入门基础
英雄联盟(撸啊撸) QQ飞车 魔兽世界等等相信大家都玩过游戏吧,玩过那UI知道是什么吧?UI可能说得有点专业的话那么游戏中那些属性面板例如: 现在对UI有一定认识了吧!回想一下您玩过的游戏就一定知道什 ...
- atitit js 开发工具 ide的代码结构显示(func list) outline总结
atitit js 开发工具 ide的代码结构显示(func list) outline总结 eclips环境::4.3.1 #-------需要一个js开发工具,可以显示outline或者代码结构显 ...
- Unity3D开发必备神器(Visual Studio Tools for Unity)
Unity3D开发必备神器(Visual Studio Tools for Unity) 开发Unity3D程序你用的什么IDE呢? 1.MonoDevelop 2.VS 可能你的回答是这样的,我用的 ...
- Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(2)
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(1)
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- 【Unity3D】Unity3D开发《我的世界》之六、创建地形(视频 + 源码)
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/unity_minecraft_06.html 一.引入LibNoise 虽然Unity3D里也有一个Mathf.P ...
- 添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三)
添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三) 猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blo ...
随机推荐
- SVN服务器搭建 内网可用外网不可用的问题
检查1:内网端口映射到了外网端口,这样外网才能够访问到 映射的方式有两种: 1.通过路由器的虚拟服务器功能,网上一搜一大把. 2.将路由器的DMZ功能开启,并把DMZ主机设置为目标计算机. 检查2:S ...
- Python,计算 ax^2 + bx + c = 0的根
1 #-*-coding : utf-8-*- 2 import math 3 4 def quadratic(a, b, c): 5 if not isinstance(a, (int, float ...
- gdb如何保存和读取断点
刚开始在linux下学编程使用gdb的同学可能会发现,每次用gdb设置断点调试程序,但下次打开的时候所有断点都没有了,很不方便.下面介绍保存和读取断点的方法. 1. 保存断点 先用info b 查看一 ...
- Python基础:基本数据类型
python基本标准6类数据类型:Number数字, String字符串, List列表,Tuple元组,Set集合,Dictionary字典 不可变数据3个(Number数字,String字符串,T ...
- HDU_2955_Robberies_01背包
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Win7访问不了WINXP共享文件
用win xp的机器可以访问,但用win 7的机器无法访问共享文件 提示:您没有权限访问.请与网络管理员联系请求访问权限 网上找了相应的资料 做了如下动作 1. 打开网上邻居→本地连接→属性里,“看是 ...
- centos7安装个人博客wordpress
第一步: 安装apache web 第二步: 安装MariaDB数据库 第三步: 安装PHP 第四步: 安装phpMyAdmin 第五部: 创建数据库: 第六部: 下载wordpress 第七部:复制 ...
- 重启rsyncd
systemctl restart rsyncd.service
- CMU Database Systems - Two-phase Locking
首先锁是用来做互斥的,解决并发执行时的数据不一致问题 如图会导致,不可重复读 如果这里用lock就可以解决,数据库里面有个LockManager来作为master,负责锁的记录和授权 数据库里面的基本 ...
- java jvm eclipse 性能调优
低配配置 -Dfile.encoding=UTF-8-Xms960m-Xmx960m-Xmn384m-Xverify:none-Xss256k-XX:MaxTenuringThreshold=2-XX ...