"Unity3d game development" Ugui Plugin starter Game Menu

Source: Internet
Author: User

Ugui is a new UI system that unity4.6 is starting to join, very powerful, and we'll learn about the use of Ugui together in a series of blogs. This blog will show you how to use Ugui to make a game menu and learn how to interact with Ugui controls, as follows:

Start with a new unity project, create a new scene, create a canvas canvas, and all of our UI controls are built on top of the canvas. Then create a button in the canvas below and rename it to Startbutton, and adjust the style to medium. Then copy the two parts out, put them in a position like, adjust their text and color, size and so on.

Next, create a new toggle underneath the canvas, which is similar to the checkbox's functionality. The style to set it to. Then in a new slider, set its parameters as shown:

Next we want to design the game bulletin Board panel, it is composed of three image,2 text, a scrollbar.

  

First, create a new image, rename it to note, set its size as shown, then create a new image underneath it and name it TITILEBG, set it to purple, place it at the top of the note, and create a new text underneath TITILEBG. Set the content to the bulletin board, and then continue to create a new image under the note, name it content, and use it to host our announcements. Then create a new text underneath the content, and then assign the text to a longer text, and lengthen the text to show all the text content. In order for the text to have scrolling function, we want to add a scroll Rect to the content, just tick vertical so that the text can only move vertically, and the content property is set to text text, so you have the ability to scroll. To make the unwanted parts appear, we need to add a mask component to the content.

Then let's design a slider for the bulletin board, create a new scroll Bar below the note, set his direction to bottom to Top, and then add the vertical in the content The ScrollBar property is set to the scrollbar we just created.

For convenience, we create a new empty object to mount the script, create a new empty object, name it Gamemanager, and then mount a script for it, with the following code:

1 /*2 Projectname:ugui's Game menu3 Author: Horse lad4 Blog:http://www.cnblogs.com/msxh/5 Github:Https://github.com/XINCGer6 DATE:2016/09/147 */8 usingUnityengine;9 usingSystem.Collections;Ten  One  Public classGamemanager:monobehaviour { A  -     //Use this for initialization -     voidStart () { the      -     } -      -     //Update is called once per frame +     voidUpdate () { -      +     } A  at      Public voidOnstartgame (stringscenename) { - Application.loadlevel (scenename); -     } -      Public voidOnstartgame (intSceneindex) { - Application.loadlevel (sceneindex); -     } in}
View Code

There is only one overloaded onstartgame function, which is used to load the new scene. Bind the Onstartgame function to the Startbutton ONCLIKC event, then set the parameter to "game" (the name of the next scene), run the preview, and click Start to jump to the game scene.

The main part of the game scene is only one cube (renamed to Player) and a slider, and we'll use them to learn how control interacts. Add a script to the player with the following code:

1 /*2 Projectname:ugui's Game menu3 Author: Horse lad4 Blog:http://www.cnblogs.com/msxh/5 Github:Https://github.com/XINCGer6 DATE:2016/09/147 */8 usingUnityengine;9 usingSystem.Collections;Ten  One  Public classPlayer:monobehaviour { A  -      Public floatSpeed=90f; -     //Use this for initialization the     voidStart () { -      -     } -      +     //Update is called once per frame -     voidUpdate () { +Transform. Rotate (vector3.forward*time.deltatime*Speed ); A     } at  -      Public voidChangespeed (floatnewspeed) { -Speed =Newspeed; -     } -}
View Code

This script can control the rotation speed of the cube, which has a changespeed function to change the speed. The OnValueChanged event of the slider is then assigned to the Changespeed function, so that the slider notifies the Changespeed function to change the rotation speed of the speed,cube as it slides.

  

The project of this blog has been synchronized to github:https://github.com/xincger/unity3dtraining/tree/master/uguitraining/uguidemo01

Horse Lad
Source: http://www.cnblogs.com/msxh/p/5921776.html
Please respect the results of other people's work, let the sharing become a virtue, welcome reprint. In addition, the article in the expression and code, if there is inappropriate, welcome criticism. Leave your footprints and welcome the comments!

"Unity3d game development" Ugui Plugin starter Game Menu

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.