http://blog.csdn.net/xiaoxiao108/article/details/37882295 unity3d用的人挺多,本来想写个3d游戏试试,额,貌似挺麻烦,先用unity写个简单的2d游戏吧 (adsw回车 或者 触摸屏虚拟摇杆) 开发环境 unity4.5.1f3 vs2013 express win8.1 实现方法如下 1.创建自己的坦克Sprite 2.创建敌方坦克Prefab 3.创建子弹Prefab 4.添加虚拟摇杆 5.碰撞检测 具体实现 1.控制自己坦克的代码 [csharp] view plaincopy if (Input.GetKey (KeyCode.W)) { Rotate (0); } else if (Input.GetKey (KeyCode.S)) { Rotate (180); } else if (Input.GetKey (KeyCode.A)) { Rotate (90); } else if (Input.GetKey (KeyCode.D)) { Rotate (270); } i++; if (i == 10) {i=0; if (Input.GetKey (KeyCode.Return)||rotateJoystick.tapCount > 0) { m.tag = "GOOD"; Instantiate (m, transform.position, transform.rotation); } } 2.控制地方坦克的代码 [csharp] view plaincopy if (step == 0) { int i=Random.Range(0, 4); Rotate(angles[i]); step = Random.Range(0, 20) + 85; if(Random.Range(0,50)>40) { m.tag="BAD"; Instantiate(m, transform.position, transform.rotation); } } else { step--; } transform.Translate (Vector3.up*Time.deltaTime*4); 3.控制子弹移动 transform.Translate (Vector3.up * Time.deltaTime * 10); 4.虚拟摇杆用的Untiy 里面 Standard Assets(Mobile).unityPackage自带的 5.碰撞检测代码 [csharp] view plaincopy void OnTriggerEnter2D(Collider2D mCollider) { if ((mCollider.gameObject.tag == "Enemy"&&gameObject.tag=="GOOD")||(mCollider.gameObject.tag == "Player"&&gameObject.tag=="BAD")) { Destroy(mCollider.gameObject); Destroy(this.gameObject); if(gameObject.tag=="BAD") { PlayerPrefs.SetString("key","OVER"); Application.LoadLevel(1); } } } 如果你发现有什么不合理的,需要改进的地方,请留言。 http://blog.csdn.net/xiaoxiao108/article/details/37882295
- 1
- 2
- 粉丝: 60
- 资源: 23
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助