Unity3D——个人游戏Car的游戏中控制
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Unity3D——个人游戏Car的游戏中控制,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3461字,纯文字阅读大概需要5分钟。
内容图文
![Unity3D——个人游戏Car的游戏中控制](/upload/InfoBanner/zyjiaocheng/1081/3b308253ce8e41cba00ac5d802500608.jpg)
/////////////////////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
内容总结
以上是互联网集市为您收集整理的Unity3D——个人游戏Car的游戏中控制全部内容,希望文章能够帮你解决Unity3D——个人游戏Car的游戏中控制所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。