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中
相关文章推荐
- 关于unity中使用Vuforia制作AR场景如何设置自动对焦的问题(全网独家)
- 【Unity&2D】使用Unity制作2D像素游戏用到的使用插件
- 教程:如何使用Unity制作3D版iOS游戏
- 【Unity 3D 游戏引擎】使用 2DToolkit 插件 制作2D精灵动画
- 【unity】【游戏开发】使用NGUI制作可以左右切换的菜单
- 使用Unity制作游戏关卡的教程(三)
- [小菜鸡学unity3D] 如何简单的制作游戏技能CD效果
- 简单两步使用Unity制作ZigZag游戏
- Unity游戏开发使用Assetbundle加载场景实战
- Unity游戏开发使用Assetbundle加载场景实战
- 使用Unity制作俄罗斯方块游戏
- wp7使用Cocos2d-X for XNA制作一个塔防类游戏 (一)游戏基础场景搭建
- 横版游戏制作之英雄技能CD遮罩,人物头像血条属性
- Cocos3.4 横版游戏制作-《KillBear》-技能及CD实现
- 分享使用Unity制作游戏关卡的教程(1)
- Unity游戏开发使用Assetbundle加载场景实战
- 开发者分享使用Unity制作2D游戏的技巧
- Unity制作游戏中的场景
- Unity2d 弱联网游戏制作(二) 动画、场景、渲染层、碰撞检测、音乐播放
- 分享使用Unity制作游戏关卡的教程(2)