Book Image

Learning NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

Learning NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (17 chapters)
Learning NGUI for Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Close buttons


Our windows are draggable pop ups; we should add a close button in the top-right corner:

In order to do this quickly and easily, we can use a component called UIForward Events. It's a legacy component—it is now recommended that you use UIEvent Trigger instead. We'll try both because it's good that you understand how they work.

Before we continue, let's create the close button for our main menu:

  1. Select our UI Root | Main | Buttons | Exit GameObject.

  2. Hit Ctrl + D to duplicate it.

  3. Rename the new duplicate to Close.

  4. Remove its attached UIPlay Tween component.

  5. Change the UISprite Size to 100 x 100.

  6. Set its Transform position to {800, 400, 0}.

  7. Select our UI Root | Main | Buttons | Close | Label GameObject.

  8. Rename it to X.

  9. Set its UILabel Text to a lowercase x character to look like a cross.

  10. Change its UILabel Font Size to 55.

The close button is ready. Let's see how the UIForward Events component works.

UIForward events

This (legacy) component is very simple to use. You just have to select which...