Unity3d with a lot of people ... Originally wanted to write a 3d game to try. Amount: Looks like a lot of trouble .... Let's write a simple 2d game with unity.
(ADSW return or touch screen virtual joystick)
Development environment UNITY4.5.1F3 VS2013 Express win8.1
The implementation method is as follows
1. Create your own tank sprite
2. Create enemy Tank Prefab
3. Create a bullet prefab
4. Add Virtual Joystick
5. Collision Detection
Specific implementation
1. Control the code of your tank
if (Input.getkey (KEYCODE.W)) {Rotate (0);} else if (Input.getkey (KEYCODE.S)) {Rotate (+);} else if (Input.getkey ( KEYCODE.A) {Rotate (+),} else if (Input.getkey (KEYCODE.D)) {Rotate (270);} I++;if (i = = ten) {i=0;if (Input.getkey (keycode.return) | | Rotatejoystick.tapcount > 0) {m.tag = "good"; Instantiate (M, Transform.position, transform.rotation);}}
2. Control the local tank code
if (step = = 0) {int i=random.range (0, 4); Rotate (angles[i]); step = Random.range (0, +) + 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. Control Bullet Movement
Transform. Translate (vector3.up * time.deltatime * 10);
4. Virtual joystick with untiy inside Standard Assets (Mobile). Unitypackage comes with
5. Collision Detection Code
void ontriggerenter2d (collider2d mcollider) {if ((MCollider.gameObject.tag = = "Enemy" &&gameobject.tag== "good ")|| (MCollider.gameObject.tag = = "Player" &&gameobject.tag== "bad")) {Destroy (Mcollider.gameobject);D Estroy (This.gameobject), if (gameobject.tag== "bad") {playerprefs.setstring ("key", "Over"); Application.loadlevel (1);}}
Code Download: http://download.csdn.net/detail/xiaoxiao108/7674235
If you find any unreasonable, need to improve the place, please leave a message. Or you can contact me via [email protected], thank you very much.