Use Unity3d 5.3.4 to mimic 2D game flappybird (i)

Source: Internet
Author: User

First, this is the resource that this article might use: Http://pan.baidu.com/s/1nvxSW6P password: ghy6

Then we open unity to create a 2D game, first create some common folders, audios (audio), materials (material), prefabs (prefabricated), textures (picture), Scenes (Scene), Scripts (script). Others do when they are created. Then import the resources into the appropriate folder. Note: To convert the imported picture type to a sprite in unity, let it support transparent format, other texture.

Create a new view in Game view with a size of 720 x 1280, and now most phones are this resolution, after all, we are imitating.

At this point, drag into a BG picture, adjust the appropriate size, we modify the sorting Layer (different levels of the display order) and the order in layer (the same level of the real order). Add a sorting layer name of background, modify the sorting layer for BG to background,order in layer to-2.

Drag a back picture as a sub-object of BG, as they are all backgrounds, can be put together, also adjust the size and sorting layer and Order in layer, add a box collider2d for it to detect and the birds collide, The size is just the right parcel to the real floor. The following should be done after the adjustment:

Note: The size of the picture here is slightly larger than the camera range, to prevent gaps between the pictures and look ugly. We then dragged the well-done BG into the Prefabs folder as a prefabricated object. Easy to re-use.
Then we dragged two prefabricated bg to the scene, named Bg_1 and bg_2, three BG position respectively (0,0,0) and (4.81,0,0) and (9.62,0,0), so that the stitching is for the sake of beauty, but also to allow the background loop to play. The scenario is as follows:

Drag into two pictures pipe, named Pipe_up,pipe_down,scale y set to 2 (that is, increase its length, convenient operation), sorting layer for background and order in layer for 1, they add box Collider2d, can wrap the picture on the line. Then reset their position by dragging to find a suitable spacing (you feel fit on the line) for the birds to pass. (My own spacing is 12, that is, their Y values differ by 12)
Then create a new empty gameobject, name pipe, reset position, as their parent object. Under the pipe, create an empty object, reset the position, add the box collider2d (can increase the score when the bird collides), the name is Collider_score, resize, position is two obstacles in the middle, tick istrigger. By moving the pipe, you can move the barrier and the empty colliding body together. Finally, the pipe as a prefab. As follows:

Then you can delete the pipe on the panel. Create an empty gameobject outside the camera, named Spawn (incubator, used to create barriers). My position is (4.3,0,0).
Next deal with the pictures of the birds. Select the bird picture in textures, modify the sprite mode to multiple, click on the Sprite Editor, click Slice in the top left corner of the popup window,

In the pop-up window click on Slice, then click on the Close button in the upper right corner, tap on the pop-up window of apply (here I do not quite understand, try to do it, as if it can actually cut pictures). At this time, you can cut a continuous picture into three pictures of birds. This is used to do frame animation. You can create a Anim (animation) folder at this time.
Click on the triangle of the bird picture in the Textures folder and select the Cut three pictures (select the first one, hold down SHIFT and click the last one to select all),

Drag to the Inspector panel, select the Anim folder you just created in the popup box, We set the name to Birdfly.anim, this is the bird's flight animation, change the Inspector panel name is bird, go to the Anim folder to modify the name of the controller is also bird. This time you can double-click the controller to see if the animation is added successfully, if not successful, drag into the line, and whether the animation loop playback is not a word to select the line.
At this time the bird can not be displayed, select bird, add sorting layer name for the player, the bird changed to this, it is possible to display, add a box collider2d to him. When you click Run, you should see the effect.

This is basically the beginning of the work, limited to the length of the rest of the blog in other posts continue.
This blog is used as a beginner to study the discussion, if there are bad or wrong place also please point out, thank you.

Project projects have been published in the last blog, Welcome to watch.

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.