您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
今天开始用Unity3D做一下水果忍者的游戏,Keep study very day!
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
需要工程文件的请留言!
今天将昨天的版本做了一些自适应的修改:
GUITexture的屏幕自适应:
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; } } } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。