Ngui achieve Skill CD effect

Source: Internet
Author: User

Using the matte effect of a sprite in Ngui makes it easy to achieve the skill CD effect.

Specific implementation steps:

① Create a new Skill001 in the sprite of the skill icon, and then add a sprite to mask the skill Sprite, and Atlas selects a picture of a plain gray background, in the Shade_sprite.

② has three properties in the matte sprite to control the effect of the mask.

Type:filled

Fill dir:radial360

Fill amount:0

Slide the fill Amount to see the effect.

③ a script that binds a shortcut key or button to a skill game object

Add a Box collider and a Ngui button script UIButton on the skill sprite, give the button an OnClick event, and refer to the Uieventlistener usage of Ngui event listener

 Public classSkill:monobehaviour {//Cooling Time     Public floatColdtime =1f; //whether it is cooling    Private BOOLIscolding =false; PrivateUisprite Shade_sprite; voidAwake () {//var skill001_shade = Gameobject.find ("UI root/skill_window/skill_border/skill001/shade_sprite"); //shade_sprite = skill001_shade.getcomponent<uisprite> ();Shade_sprite = GameObject.transform.Find ("Shade_sprite"). Getcomponent<uisprite>(); Uieventlistener.get ( This. gameobject). OnClick + =Startskill; }    voidUpdate () {if(Input.getkey (KEYCODE.N) &&!iscolding) {            //TODO trigger skills, skill effects, etc.Shade_sprite.fillamount =1; Iscolding=true; }        if(iscolding) {Shade_sprite.fillamount-= (1f/coldtime) *Time.deltatime; if(Shade_sprite.fillamount <=0.001) {Shade_sprite.fillamount=0; Iscolding=false; }        }    }    voidStartskill (Gameobject go) {if( !iscolding) {            //TODO trigger skills, skill effects, etc.Shade_sprite.fillamount =1; Iscolding=true; }    }   }

Ngui achieve Skill CD 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.