Unity制作技能冷却效果

发表于2017-05-13
评论1 2.9k浏览

在很多类型的游戏中,主角的技能需要等到技能冷却才能释放,那么这种人物技能冷却效果是怎么开发出来的呢,下面就给大家介绍下在Unity中简单实现技能冷却效果的方法。

【Mask组件的使用】

首先制作技能图标

创建一个UI->Image

Image选择Unity自带的圆形图片

在Image下添加一个按钮作为子节点,并适当放大按钮

选择一张精灵图片作为按钮图案

在Image下添加Mask组件

Mask中文名叫面具

该组件的作用是 只显示Image与子节点重合部分的图案


这样一个简单的圆形技能图标做好了

【技能计时器】

所谓技能计时器是在技能冷却时一层半透明图标旋转效果


继续往Canvas画布上添加一个Image

将该Image的Color属性设置为黑色并半透明

将Image Type属性改动为Filled(具体如下图)


这样改变Fill Amount值,将改变旋转大小

这里注意的是,取消Raycast Target属性的勾选,不然按钮将不能接收响应

【代码控制】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
   
public class SkillCoolingManager : MonoBehaviour  
    //冷却周期 
    public float coolingTimer = 2.0f; 
   
    private float currentTime = 0.0f; 
   
    //冷却图片 
    public Image coolingImage; 
   
    // Use this for initialization 
    void Start ()  
    
        currentTime = coolingTimer; 
    
       
    // Update is called once per frame 
    void Update ()  
    
        if (currentTime < coolingTimer) 
        
            currentTime += Time.deltaTime; 
            //按时间比例计算出Fill Amount值 
            coolingImage.fillAmount = 1 - currentTime / coolingTimer; 
        
    
   
    public void OnBtnClickSkill() 
    
        if (currentTime >= coolingTimer) 
        
            currentTime = 0.0f; 
   
            coolingImage.fillAmount = 1.0f; 
        
    
}



Mask组件的使用方法可以在制作小地图时运用到

这样一个简单技能冷却效果制作完毕,技能图片简陋,多多包涵!!!

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引