您的位置:首页 > 移动开发 > Unity3D

Unity制作游戏中技能使用后转CD的场景

2017-08-30 08:58 731 查看


因为我们需要用鼠标点击图片让它重新转CD,所以我们需要创建一个Button,然后把Button的子物体Test删除掉,加一个Image为他的子物体。



然后我们把图片(这里图片必须是 Sprite (2D and UI)格式的)拖入到Button 的Source Image中,同时拖入到Image的Source Image中,然后在Image中他调整它的颜色,并且改变它的Image Type为Filled,这里颜色自己调整,设置如下图



为了达到点击图片转CD的效果写了脚本:

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

public class CDHyp : MonoBehaviour {
//剩余时间
public float leftTime;
//CD转完的总时间
public float totalTime;
private Image effectImage;
private Button cdButton;

// Use this for initialization
void Start () {
effectImage = transform.FindChild("Image").GetComponent<Image>();
//    effectImage = GetComponent<Image>();
leftTime = totalTime;
cdButton = transform.GetComponent<Button>();
cdButton.interactable = false;
}
// Update is called once per frame
void Update () {
leftTime -= Time.deltaTime;
if (effectImage.fillAmount>0)
{
effectImage.fillAmount = leftTime / totalTime;
}
else
{
effectImage.fillAmount = 0;
cdButton.interactable = true;
}
}
public void FireSkillHyp()
{
Debug.Log("技能使用");
leftTime = totalTime;
cdButton.interactable = false;
effectImage.fillAmount = 1;
}
}


另外,这里我们还需要把脚本中FireSkillHyp这个事件添加到Button中

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: