[unity3d]水果忍者-界面搭建
今天开始用Unity3D做一下水果忍者的游戏,Keep study very day!
效果图:
实现步骤:
1.贴图的创建
2.声音的添加
3.手动“绘制”按钮
using UnityEngine; using System.Collections; public class start : MonoBehaviour { public GUISkin mySkin; private bool isSound1Button = false; private bool isSound2Button = true; private AudioSource sound; private float screenwitdh; private float screenheight; public GUITexture background; public GUITexture title; void Awake() { // screenwitdh = Screen.width; // screenheight = Screen.height; //想改变背景的分辨率 // background.guiTexture.pixelInset.x = 0; // background.guiTexture.pixelInset.y = 0; // background.guiTexture.pixelInset.width = screenwitdh; // background.guiTexture.pixelInset.height = screenheight; } // Use this for initialization void Start () { sound = gameObject.GetComponent<AudioSource>(); } void OnGUI() { screenwitdh = Screen.width; screenheight = Screen.height; GUI.skin = mySkin; //这里的GUI坐标是以左上角为原点跟GUITexture的坐标不同,GUITexture属性中是OpenGL坐标是从左下方开始为原点 if (GUI.Button(new Rect(screenwitdh/2-110, screenheight -280, 220, 66), "", GUI.skin.GetStyle("playbutton"))) { Application.LoadLevel(1); } if(GUI.Button (new Rect(screenwitdh/2-160,screenheight -200,320,66),"",GUI.skin.GetStyle("MoreButton"))) { Application.OpenURL("http://blog.csdn.net/dingxiaowei2013"); } if(GUI.Button(new Rect(screenwitdh/2-100,screenheight -120,200,66),"",GUI.skin.GetStyle("CreditButton"))) { Application.OpenURL("http://blog.csdn.net/dingxiaowei2013"); } if(isSound1Button) { if(GUI.Button(new Rect(45,screenheight-45,20,31),"",GUI.skin.GetStyle("Sound1Button"))) { sound.Play(); isSound1Button = false; isSound2Button = true; } } if(isSound2Button) { if(GUI.Button(new Rect(45,screenheight-45,37,31),"",GUI.skin.GetStyle("Sound2Button"))) { sound.Stop(); isSound1Button = true; isSound2Button = false; } } } }
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:858550 cocos2dx QQ群:280818155
====================== 相互学习,共同进步 ===================
转载请注明出处:http://blog.csdn.net/dingxiaowei2013/article/details/18376397
欢迎关注我的微博:http://weibo.com/u/2590571922
screenwitdh = Screen.currentResolution.width; screenheight = Screen.currentResolution.height; //改变背景的分辨率 background.transform.position = Vector3.zero; background.transform.localScale = Vector3.zero; background.guiTexture.pixelInset = new Rect(0, 0, screenwitdh, screenheight); print("height" + screenheight); print("width" + screenwitdh);
using UnityEngine; using System.Collections; public class start : MonoBehaviour { public GUISkin mySkin; private bool isSound1Button = false; private bool isSound2Button = true; private AudioSource sound; private float screenwitdh; private float screenheight; public GUITexture background; public GUITexture title; void Awake() { screenwitdh = Screen.currentResolution.width; screenheight = Screen.currentResolution.height; //改变背景的分辨率 background.transform.position = Vector3.zero; background.transform.localScale = Vector3.zero; background.guiTexture.pixelInset = new Rect(0, 0, screenwitdh, screenheight); //title.transform.position = Vector3.zero; //title.transform.localScale = Vector3.zero; //坐标是以左下角为原点开始的,锚点也是左下角 float width = 400; float height = 200; title.guiTexture.pixelInset = new Rect(screenwitdh/2-width/2, screenheight-30-height, width, height); print("height" + screenheight); print("width:" + screenwitdh); } // Use this for initialization void Start () { sound = gameObject.GetComponent<AudioSource>(); } void OnGUI() { //screenwitdh = Screen.width; //screenheight = Screen.height; GUI.Label((new Rect(10, 10, 100, 20)), "作者:丁小未"); GUI.Label((new Rect(10, 30, 100, 20)), "height:"+screenheight.ToString()); GUI.Label((new Rect(10, 50, 100, 20)), "widht:"+screenwitdh.ToString()); GUI.skin = mySkin; //这里的GUI坐标是以左上角为原点跟GUITexture的坐标不同,GUITexture属性中是OpenGL坐标是从左下方开始为原点 if (GUI.Button(new Rect(screenwitdh/2-110, screenheight -250, 220, 66), "", GUI.skin.GetStyle("playbutton"))) { Application.LoadLevel(1); } if(GUI.Button (new Rect(screenwitdh/2-160,screenheight -185,320,66),"",GUI.skin.GetStyle("MoreButton"))) { Application.OpenURL("http://blog.csdn.net/dingxiaowei2013"); } if(GUI.Button(new Rect(screenwitdh/2-100,screenheight -120,200,66),"",GUI.skin.GetStyle("CreditButton"))) { Application.OpenURL("http://blog.csdn.net/dingxiaowei2013"); } if(isSound1Button) { if(GUI.Button(new Rect(60,screenheight-60,30,41),"",GUI.skin.GetStyle("Sound1Button"))) { sound.Play(); isSound1Button = false; isSound2Button = true; } } if(isSound2Button) { if(GUI.Button(new Rect(60,screenheight-60,45,41),"",GUI.skin.GetStyle("Sound2Button"))) { sound.Stop(); isSound1Button = true; isSound2Button = false; } } } }
效果图
[unity3d]水果忍者-界面搭建相关推荐
- unity3d水果忍者制作
unity3d水果忍者制作 接着昨天的更新,代码实现模块的理解和实现,这里对ui和声音部分就不做过多解释,主要讲解游戏场景内代码的实现功能: 在一个游戏制作过程中预制体的巧妙使用和删减可以帮我们节省大 ...
- [Unity3d]水果忍者-声音和刀光的实现
继续水果忍者制作,写一下今天的学习心得,主要就是实现了一个切水果的刀光以及声音的实现. 主要效果 实现步骤 1.实现划线 原理:主要是用到Effet->Line Renderer组件(线渲染器) ...
- [Unity3d]水果忍者-切水果功能
继续今天的切水果游戏之切苹果的实现,主要功能就是,有一个苹果放在场景中,然后通过手滑过苹果,就将苹果切成两半,从原理上分析,就是制作两张贴图,分别表示分开的两半苹果,然后在当前位置出现,并且给这两半苹 ...
- 2017级C语言大作业 - 水果忍者
水果忍者 C语言作业 分享17级同学大一上学期用C语言实现的水果忍者.分步骤代码.图片音乐素材.可执行程序可从百度网盘下载: 链接:https://pan.baidu.com/s/1i-e_MVChl ...
- 使用Coco2d-x2.2.3版本开发水果忍者游戏环境配置
一.Cocos2d-x-2.2.3版本安装配置. 1.在Cocos2D-X 2.2.3目录下,点击cocos2d-win32.vc2010.sln. 由于我的电脑上安装了vs2019,点击后是用的vs ...
- Unity3D制作注册登录界面,并实现场景跳转
效果预览图片: 效果预览视频: 一.新建项目工程 1.打开Unity3D,新建一个项目,将其命名为"Login".我这里用的版本是Unity2018.4.2f1,不同版本制作过程中 ...
- android 水果忍者源码,Fruit Ninja(水果忍者)游戏源代码下载、分析(下)---可运行Android,Ios,Window,Mac,Html5平台...
背景: 这一篇是结尾篇,主要分析×××检测,游戏结束和保存最高分: ps: 1 CocosEditor已发布新版本,现在提供6个实战demo学习,包括flappy ,popstar ,fruitnin ...
- unity水果忍者制作
unity水果忍者制作 这几天学了一下切水果游戏的手游制作,大致了解操作运行过程,还在制作当中就先写一篇自己的思路吧: 首先收集和制作好ui素材,这些是一个项目开始的基石也是整个游戏最直观的东西,然后 ...
- 《游戏学习》| 水果忍者HTML5网页版在线游戏 | 源码分析
游戏介绍 这是一款由百度JS小组提供的HTML5版切水果游戏,这款基于HTML5实现的网页版切水果游戏虽然和原版的切水果游戏相比仍有美中不足之处,但也算有声有色,画面效果也十分炫目华丽. 游戏截图 主 ...
最新文章
- shell中的特殊变量
- python链接安卓 跳一跳
- C# TCP sever client
- R有序因子和无序因子(4)
- 几个复制表结构和表数据的方法
- Master of GCD(差分数组||线段树)
- 五个使Java变得更好的功能
- PCA主成分分析学习总结
- Java对象垃圾回收调用,JVM垃圾回收之哪些对象可以被回收
- 刷爆了!李彦宏:这类程序员我给100万!你怎么看?
- extJS 中 ext.data 介绍
- windows下sublime2 clojure环境配置
- centos7安装源疯了_Jenkins 在 Centos7 上安装(使用国内源)
- 拓端tecdat|R语言Lasso回归模型变量选择和糖尿病发展预测模型应用(含练习)
- python课程设计小结和体会_关于课程设计心得体会
- H5网页去除苹果手机底部白边
- Hive集合数据类型(STRUCK,MAP,ARRAY)
- 狂神说Spring学习笔记————(一发入魂)
- JS在VS coder界面写promt和alter语句无法在浏览器页面显示
- Banner在线制作网站介绍以及如何Springboot中使用
热门文章
- 华为正式发布自有操作系统鸿蒙OS
- 高层定调!铁腕控炒房,2019下半年楼市基本不会涨了
- 谷歌的AI应用开发之道
- 「AI不惑境」深度学习中的多尺度模型设计
- 外媒评李开复的《AI·未来》:四大浪潮正在席卷全球
- SAP MM Overall Level 审批的采购申请中行项目里的成本中心必须是同一个!
- (深入理解)matplotlib的交互模式(block,interactive,ion,ioff,draw,show,plot等的区别)
- 为啥辣椒会辣得人嘴巴疼?这个问题竟然和今年诺奖有关
- 机器学习漫谈:还有很长的路要走
- 科普|深度解析5G与未来天线技术