Unity + win8.1 Apps mini Game demo

Source: Internet
Author: User

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.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.