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 ...
随机推荐
- Spring.Net学习笔记(6)-方法注入
一.开发环境 系统:win10 编译器:VS2013 二.涉及程序集 Spring.Core.dll 1.3.1 Common.Logging.dll 三.开发过程 1.项目结构 2.编写Mobile ...
- PostgreSQL 流复制+高可用
QA PgPool-II 同步 Postgresql X1 服务器准备 192.168.59.121 PostgreSQL10 192.168.59.120 PGPool-II 3.7 X2 安装Po ...
- 使用纯css鼠标移入效果,炫酷的旋转正方体
首先我们需要创建几个盒子 </div> <div class="wrap"> <div class="cube"> < ...
- jQuery伪分页效果
如图,我们首先分析在一个页面存放4条内容,其余的超出隐藏(因为这里没有后台数据,所以我们把内容‘写死’),然后就是下面两个按钮(这里我们不用button,因为button有自带的提交功能),然后我们可 ...
- Python学习日记之忽略删除字符串空白
使用Python自带的函数strip可以剔除字符串开头.结尾.两端的空白 使用场景:用户输入验证 strip : 去除字符串两端的空白 rstrip : 去除字符串末尾(右端)的空白 lstrip : ...
- JavaScript判断
if...else: if...else语句是在指定的条件成立时执行的代码,在条件不成立时执行else后的代码. 语法: if(条件) {条件成立时执行的代码 }else{ 条件不成立的时执行的代码} ...
- HTML 5 <aside> 标签
定义和用法 <aside> 标签定义 article 以外的内容.aside 的内容应该与 article 的内容相关. 实例 <p>Me and my family visi ...
- 在CorelDRAW中的自定义彩虹笔刷创建迷幻背景
在60年代的艺术形式中,迷幻艺术对设计和图形艺术的影响尤为重要.在下面这个CorelDRAW教程中我们主要使用图形纸工具和艺术笔工具创建一个迷幻风格的背景,在这之前我们需要先创建出一个彩虹笔刷. 1. ...
- 06C语言运算符
C语言运算符 算术运算符 运算符 描述 + 把两个操作数相加 - 从第一个操作数中减去第二个操作数 * 把两个操作数相乘 / 分子除以分母 % 取模运算符,整除后的余数 ++ 自增运算符,整数值增加 ...
- 16Log4J
Log4J Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事件记录器.UNIX Syslog守 ...