Recently in the study Ngui, some small knowledge points, personally feel very good, on record down, after all, good memory than rotten pen, restudying.
- First import the Ngui plugin, plugin I will give the link below the article.
- After importing Ngui, will see the Ngui button in the menu bar, we first create a sprite, rename it to skill, select the Atlas and sprite for it, adjust the skill size and position, I here size for 200*200.
- Select the skill in the hierarchy panel, then in the scene panel, right-Create a sprite, rename it to filled, select the Atlas and sprite for it, preferably a monochrome sprite, then type select filled (core), modify color Tint , for black, to adjust the transparency to a suitable position, I am here for 100, (can self-grasp).
- In the hierarchy panel, select Skill, then in the scene panel, right-Create a lable, rename it to time, select the font for it, then modify the font size (40), and Size (80*50), adjust its position so that it is centered, add a border to it, In effect where to select outline, modify the border color, make it look better, and finally delete the contents of text.
- In the hierarchy panel, select Skill, then in the scene panel, right-Create a lable, rename it to key, choose a font for it, then modify the font size (40), and Size (80*50), and then adjust its position to the lower-right corner of the skill, Modify the contents of text as a ToolTip for a skill shortcut, I'm here for a, and then I can add some effects and colors depending on your preferences. I will not add it here.
- Now I'm going to add the script to control the cooldown of the skill. Select skill, add a script, and name skill. Open the script, edit it.
Using Unityengine;
Using System.Collections;
public class Skill:monobehaviour
{
public float skillcoldtime = 5f; Cooling time, can be modified externally
Private UILabel TimeLabel; Display the countdown lable
Private Uisprite Filledsprite; Lable to display skill shortcut keys
private bool Iscold = false; Whether the cooling
Private float timer = 0f; Timer
void Start ()
{
TimeLabel = transform. Findchild ("Time"). Getcomponent<uilabel> ();
Filledsprite = transform. Findchild ("Filled"). Getcomponent<uisprite> ();
TimeLabel.gameObject.SetActive (FALSE); Do not show cooldown and skill shortcut buttons at first
FilledSprite.gameObject.SetActive (FALSE);
}
void Update ()
{
if (Input.getkeydown (KEYCODE.A) &&!iscold)//When set shortcut keys are pressed,
{
Print ("biu~biu~");
Iscold = true; Start cooling
timer = Skillcoldtime; Timer equals cooldown time
Timelabel.text = ((int) skillcoldtime). ToString () + "s"; Displays the cooldown time, where only integers are displayed
TimeLabel.gameObject.SetActive (TRUE); Activates the display cooldown time lable
Each time you press the key, reset the Fillamount to fully cover the skill icon
Fillamount is a value between 0 and 1, 0 is not displayed, and 1 is all displayed
Filledsprite.fillamount = 1f;
FilledSprite.gameObject.SetActive (TRUE); Activates the sprite of the front-facing background
}
if (iscold)
{
Timer-= Time.deltatime; Countdown
Timelabel.text = ((int) timer). ToString () + "s"; Displays the countdown, which shows only integers
Filledsprite.fillamount = Timer/skillcoldtime; Displays the scale of the experience of the front background according to the proportions,
if (timer <= 0f)//On time,
{
Iscold = false; End of cooling
TimeLabel.gameObject.SetActive (FALSE); Hide Display
FilledSprite.gameObject.SetActive (FALSE);
}
}
}} at this point, save the script, go back to the editor, we run the game, when we press the a key, we will see, like this, a simple skill cooling is OK. NGUI3.9.1: Link: Http://pan.baidu.com/s/1sjvbOBV Password: 30xf If you want to use Ngui for commercial purposes, please go to assetstore purchase genuine, thank you!
Use Ngui to make skill cooling icons