首先在制作一个sprite命名为skill加一个背景图片,然后再建立一个sprite,选择一个可以挡住skill的背景的图片,然后选择Filled属性(如下图)。然后在Sprite下面建立一个Label用来表示技能的按键快捷键,本例用的是R键。。。如下图 ![]()
![]()
因为sprite的图片挡住了skill的图片,所以给sprite的Alpha值调整到半透明,调整在color里面的属性如图(图的左边已经看到了效果);在color的上面有个 Fill Amount属性,这个属性就是负责cd效果的,只要用脚本去调整参数就可以了。
![]()
调整的脚本如下
[csharp] view plaincopy
- using UnityEngine;
- using System.Collections;
-
- public class skill_cd : MonoBehaviour {
-
- public int cdtime=2;
- private UISprite sprite;
- private bool iscolding=false ;//是否在冷却
-
- public
- // Use this for initialization
- void Awake () {
- sprite =transform .Find ("Sprite").GetComponent <UISprite >();
- }
-
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown (KeyCode.R) &&iscolding ==false )//按键R
- {
- //释放技能创建粒子系统显示技能特效
- //ui上显示cd效果
- sprite .fillAmount =1;
- iscolding =true;
- }
- if (iscolding ){
- sprite.fillAmount -= (1f / cdtime) * Time.deltaTime;
- if (sprite.fillAmount <= 0.05)
- {
- iscolding = false;
- sprite.fillAmount = 0;
- }
- }
- }
- }
最后只要把脚本拖给Skill然后运行按键盘R键就可以看到效果了。。。如图:
![]()
|