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