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]