Book Image

NGUI for Unity

By : Charles Bernardoff
Book Image

NGUI for Unity

By: Charles Bernardoff

Overview of this book

Table of Contents (14 chapters)

Sending messages

The Notify parameter in the Inspector window we used in previous chapters to call methods on a precise event is usually enough for sending messages. However, you may need to send a message to another GameObject and maybe to its children too.

That's where the UIButton Message component comes in handy. We will use this to make our MainMenu GameObject scale down before the game actually quits:

  1. Select our Exit GameObject and perform the following steps:

    1. Attach a Button Message component to it by navigating to Component | NGUI | Interaction.

    2. Drag our Container GameObject from MainMenu into its Target field.

    3. Type in CloseMenu in the Function Name parameter.

  2. Select our Container GameObject in MainMenu and open its attached AppearFromAbove.cs script.

In this script, add a simple CloseMenu() method containing the following lines:

void CloseMenu()
  //Tween the menu's scale to zero
  TweenScale.Begin(this.gameObject, 0.5f,;

Now we need to delay the execution of the Application...