标签:
/////////////////////2015/08/25///////////////
////////////////////by XBW/////////////////////
///////////////////环境 unity4.6.1///////////
终于弄完了这个停车游戏,先看一下效果图
这个游戏呢,就是在赛道内收集三枚以上氮气,然后再返回起点,在赛车损坏程度内完成就算胜利,我们只做了安卓版,用陀螺仪控制赛车的前进以及左右,碰撞的检测以及UI我写在了Control.cs中,直接挂在给塞车了,其中赛车的tag为Player,氮气的tag为danqi,下面直接上代码了;
using UnityEngine; using System.Collections; public class Control : MonoBehaviour { // Use this for initialization private int danqi = 0; private float life = 100; private int right = 1; private int jieshu = 1; public GUISkin GUIskin; public GUISkin GUIskin2; public Texture2D img1; public Texture2D img2; void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "danqi") { Destroy(other.gameObject); danqi++; } } void Start() { } // Update is called once per frame void Update() { if (transform.position.x > 138 && transform.position.x < 139 && transform.position.z > 151 && transform.position.z<154 && danqi >= 3) { right = 0; //Destroy(GameObject.FindGameObjectWithTag("Player")); Time.timeScale = 0; } life -=Time.deltaTime * 0.5f; } void OnGUI() { GUIStyle go = new GUIStyle(); go.fontSize = 30; go.normal.textColor = new Color(0, 0, 0); GUI.skin = GUIskin; GUI.DrawTexture(new Rect(Screen.width * 0.01f, Screen.height * 0.02f, Screen.width * 0.1f, Screen.height * 0.15f), img1); GUI.DrawTexture(new Rect(Screen.width * 0.72f, Screen.height * 0.02f, Screen.width * 0.1f, Screen.height * 0.15f), img2); GUI.Label(new Rect(Screen.width * 0.8f, Screen.height * 0.1f, 100, 100), "氮气 "+ danqi.ToString(), go); GUI.Label(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, 100, 100), "损坏 "+ life.ToString(), go); GUI.skin = GUIskin2; if (GUI.Button(new Rect(Screen.width - Screen.width * 0.3f, Screen.height - Screen.height * 0.15f, Screen.width * 0.3f, Screen.height * 0.15f), "再试一次")) { Application.LoadLevel(Application.loadedLevelName); } if (GUI.Button(new Rect(0, Screen.height - Screen.height * 0.15f, Screen.width * 0.3f, Screen.height * 0.15f), "不想玩了")) { Application.LoadLevel("Menu"); } //if (GUI.Button(new Rect(Screen.width - Screen.width * 0.2f, Screen.height*0.4f, Screen.width * 0.2f, Screen.height * 0.1f), "悬挂 +")) //{ // GameObject.FindGameObjectWithTag("Player").GetComponent<WheelSuspension_Script>().SpringLength+=0.1f; //} if(life<=0) { GUI.skin = GUIskin; GUI.Label(new Rect(Screen.width * 0.4f, Screen.height * 0.3f, 100, 100), "YOU LOSE", go); Time.timeScale = 0; GUI.skin = GUIskin2; if (GUI.Button(new Rect(Screen.width * 0.35f, Screen.height * 0.4f, Screen.width * 0.3f, Screen.height * 0.15f), "再试一次")) { Application.LoadLevel(Application.loadedLevelName); } if (GUI.Button(new Rect(Screen.width * 0.35f, Screen.height * 0.6f, Screen.width * 0.3f, Screen.height * 0.15f), "返回主菜单")) { Application.LoadLevel("Menu"); } } if (right == 0) { GUI.skin = GUIskin; GUI.Label(new Rect(Screen.width * 0.4f, Screen.height * 0.3f, 100, 100), "YOU WIN", go); Time.timeScale = 0; GUI.skin = GUIskin2; if (GUI.Button(new Rect(Screen.width * 0.35f, Screen.height * 0.4f, Screen.width * 0.3f, Screen.height * 0.15f), "再试一次")) { Application.LoadLevel(Application.loadedLevelName); } if (GUI.Button(new Rect(Screen.width * 0.35f, Screen.height * 0.6f, Screen.width * 0.3f, Screen.height * 0.15f), "返回主菜单")) { Application.LoadLevel("Menu"); } } } }就这么简单,有不懂的地方或者有错误的地方请留言给我,相互学习一下
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/xbw12138/article/details/47976525