技能CD与Toggle按钮设置

来源:互联网 发布:js聚合物水泥防水阴角 编辑:程序博客网 时间:2024/04/30 13:39

这里写图片描述
模拟技能cd
1.在Canvas建立Button,在其Image下的Source Image

槽中添加技能图标
2.在Button下建立Image,Image作为子物体,在其

Image组件下的Source Image槽中再次添加技能图标

设置Color值(可自定义,能分辨就好)
3.脚本加在Button上,因为他有组件On Clike可以在外

加载脚本,实现鼠标点击重复操作(下面脚本为技能CD脚本)

Toggle设置小按钮
1.添加三个Toggle按钮,在每个Toggle内的

Background下的Source Image添加精灵按钮图标框,

每个Background内的Checkmark下的Source Image添

加精灵图标按钮
2.建立一个空物体随便命名但必须放在Canvas下,然

后将三个Toggle放在空物体中作为子物体
3.点击空物体,添加ToggleGroup组件
4.全选Toggle,在Toggle下面板的 Group中选择空物

体名字,从而添加进入空物体的ToggleGroup组中
5.要实现单独选择,把三个Toggle中的面板下的两个

Is On 取消勾选
6.要实现不勾选,点击空物体取消Allow Switch off

勾选
7.要想改变文本内容,可在每个Toggle内的Lable下

的Text文本框内修改(实现功能不需要添加脚本)


using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CutCD : MonoBehaviour {
private Image image;
float cdtime = 5f;
float currentcd;
private Button button;
// Use this for initialization
void Start () {
image =GameObject.Find(“Image”). GetComponent();
button =GetComponent();
currentcd = cdtime;
}

// Update is called once per frame
void Update () {
currentcd -= Time.deltaTime;
if (currentcd < 0)
{
currentcd = 0;
}
image.fillAmount = currentcd / cdtime;
}
public void FireCD()
{
Debug.Log(“开火”);
currentcd = cdtime;
image.fillAmount = 1;
}

}

```
原创粉丝点击