经常在很多页游里面或者是DNF之类啊的游戏 很多技能是点击和键盘上面的某个键位触发的 ,现在就来制作出这个键位的问题
首先创建我们要点的图标大致的效果如下可以自己看看
然后来开始说层级
最主要的是这个面板下的Image中ImageType
要设置成Fillde
照着我的如下设计
其他的一一截图出来
然后就是代码方面
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SkillItem : MonoBehaviour
{
/// <summary>
/// 技能冷却时间
/// </summary>
public float coldTime = 2;
/// <summary>
/// 当前时间
/// </summary>
private float timer = 0;
/// <summary>
/// 技能Image
/// </summary>
private Image FilImage;
/// <summary>
/// 判断技能读条
/// </summary>
private bool IsStartTimer = false;
public KeyCode keyCode;
// Start is called before the first frame update
void Start()
{
FilImage = transform.Find("FilImage").GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(keyCode)){
IsStartTimer = true;
}
if(IsStartTimer == true)
{
timer += Time.deltaTime;
FilImage.fillAmount = (coldTime - timer) / coldTime;
}
if(timer > coldTime)
{
FilImage.fillAmount = 0;
timer = 0;
IsStartTimer = false;
}
}
public void Onclick()
{
IsStartTimer = true;
}
}
只有这一条代码
控制和挂载在第一张图里面