Unity3D——个人游戏Car的游戏中控制
来源:互联网 发布:免费cf手游刷枪软件 编辑:程序博客网 时间:2024/05/18 03:26
/////////////////////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"); } } }}就这么简单,有不懂的地方或者有错误的地方请留言给我,相互学习一下
0 0
- Unity3D——个人游戏Car的游戏中控制
- Unity3D 游戏开发构架篇 ——输入控制
- Unity3D游戏制作(一)——3D横版场景的角色移动控制
- Unity3D游戏制作(一)——3D横版场景的角色移动控制
- 个人开发Unity3d游戏中常用API函数
- Unity3D——射箭游戏
- Unity3d中有关游戏角色控制的几种实现方式
- Unity3D游戏开发之自由视角下的角色控制
- Unity3D游戏开发之自由视角下的角色控制
- Unity3D游戏开发第三人称角色控制的模式
- [Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘(中)
- [Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘(中)
- Unity3D——下一个游戏市场的主导引擎
- 游戏中CPU使用率的控制
- 控制游戏中物体的移动速度
- 控制游戏中物体的移动速度
- unity3d 中实现猜拳游戏
- Unity3d中获取游戏对象
- 简单实现JSON字符串的可视化
- Ugly Number II 寻找第N个丑数
- ntoskrnl.lib(loadcfg.obj) : error LNK2001: unresolved external symbol ___security_cookie
- 【笔试】21、二维数组中的查找
- Android 4.4 源码编译
- Unity3D——个人游戏Car的游戏中控制
- 【模拟】【暴力】[COCI]排序
- 程序员应有素质
- ios自定义构造方法
- 浅析C#中的事件
- 机房收费系统验收之思想无价
- swift中字符串截取方法(substring)
- 插入排序总结
- 【ActionBar】Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)