Unity ngui plug-in-Entry Effect

Source: Internet
Author: User

Unity ngui plug-in-entry results

The entry effect must be completed by using the tweenposition class provided by ngui. To illustrate the usage of this class, this section describes two examples. This article is based on the University's ngui user manual.

 

Uniform entry

Consider the game main menu as a whole. This section will allow them to enter the game at a constant speed from top to bottom. The specific implementation process is as follows:

(1) In the project view, create a new C # script named appearfromabove and add the following code to it:

  • 01 using unityengine;
  • 02 using system. collections;
  • 03
  • 04 public class appearfromabove: monobehaviour
  • 05 {
  • 06 // use this for initialization
  • 07 void start ()
  • 08 {
  • 09 this. Transform. localposition = new vector3 (0, 1080, 0 );
  • 10 tweenposition. Begin (this. gameobject, 2, vector3.zero );
  • 11}
  • 12}

Row 09 of the Q script modifies the initial position of the game main menu so that it is located at the top of the game view;

Script 10 rows, tweenposition. the begin () method moves the game main menu to the position where the coordinate point is (0, 0), which takes 2 seconds. This article is from the university overlord "ngui User Manual ".

(2) Assign the script to the container object and then run the game. effect 4-shown. At first there was nothing in the game view, but within two seconds, the game Main Menu would move from top to bottom at a uniform speed in the middle of the game view.


Figure 4-display of the uniform entrance effect of the game Main Menu

Tip: only two lines of code are used. Of course, the above describes how to use custom scripts. In fact, to achieve the same effect, readers can also use ngui components. This method is simpler than custom scripts. Specifically, add the Tween position (SCRIPT) component to the iner object by clicking the component | ngui | tween position command and setting the following attributes of the component, 4.

Q from :( 0, 1080, 0 );

Q to :( 0, 0, 0 );

Q Duration: 2;

Q TRANSFORM Component p :( 0, 1080, 0 );


Figure 4-tween position (SCRIPT) Component Attribute settings

Smooth entrance

At the beginning of the game, the game's main menu comes from top to bottom. It looks a little abrupt. It's better to delay it for 1 second before entering the game. Why not add other effects, such as bounce! This section describes how to implement this effect. This article is based on the University's ngui user manual.

 

(1) modify the code in the script appearfromabove. The modified code is as follows:

  • 01 using unityengine;
  • 02 using system. collections;
  • 03
  • 04 public class appearfromabove: monobehaviour
  • 05 {
  • 06 // use this for initialization
  • 07 void start ()
  • 08 {
  • 09 this. Transform. localposition = new vector3 (0, 1080, 0 );
  • 10 tweenposition tween = tweenposition. Begin (this. gameobject, 2, vector3.zero );
  • 11 tween. Delay = 1f;
  • 12 tween. method = uitweener. method. bouncein;
  • 13}
  • 14}

Q script 09 and 10 lines of code, which has been introduced in the previous section;

The Q script contains 11 rows, with a latency added. That is, the game enters the main menu one second later;

The Q script contains 12 rows and adds the effect after entry. Here, the bounce effect is used;

(2) run the game to see the smooth entrance effect of the game main menu. The difference from the previous section is mainly manifested in two aspects: one is the delay of the admission time, and the other is the animation effect after the entry. This article is based on the University's ngui user manual.

 

Tip: the animation effects provided by ngui are not just bounce effects. To learn more about the effects, you can flexibly use the "code auto-completion" function of the Script Editor, for example, in monodevelop, when writing to 12 rows of the script, the automatic completion effect is shown in 4-. It can be seen that ngui provides a total of 6 effects.


Figure 4-use the "Automatic Code Completion" function to explore other animation Effects

This article is based on the University's ngui user manual.

 

Unity ngui plug-in-Entry Effect

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.