Unity5 and UGUI little Demo greedy, unity5uguidemo

Source: Internet
Author: User

Unity5 and UGUI little Demo greedy, unity5uguidemo

Have time to learn Unity5 trainer, a little snake Demo

In a simple 2D scenario, all objects are Sprite. You need to set the display level before and after. The value of Order in Layer from the snake header to the snake tail is 1000 and 1, therefore, the display effect is layered with scales.

Each section of the snake contains a script named "SnakePart. cs" to record the position and direction of this section, including the calculated value.

If a snake does not eat an apple, it will instantiate and generate a section. The newly generated section contains a new script newsnkepart. the main function of cs is to initialize and add this section to the end of the snake, including the initialization position and direction.


GameManager. cs Singleton class, List <SnakePart> is all the sections of the snake, and randomly generates food. The game ends and starts again, positions of each section are converted from the end to the end ).

Finally, the PlayerScript. cs script is mounted on the snake head. Let's talk about the operation of the game first, that is, dragging the snake head with the mouse (or finger) so that the snake will move. The role of this script is to calculate the distance and direction that each section should move forward. There is also a collision detection, which detects eating apple, hitting the wall, and biting yourself.

In the game, only the snake header has both the rigidbody and the collider, and the others only have the collier. This is the condition for collision detection by the unity physical engine. Both sides must have a collision body and the moving object must have a rigid body.


As for the GameOver UI, the original UGUI of Unity5 is used.

The script has minor differences in versions earlier than Unity5.


[End]

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.