纳金网
标题:
多个技能冷却的代码
[打印本页]
作者:
狂风大尉
时间:
2014-8-28 00:50
标题:
多个技能冷却的代码
感觉这个方法适合技能较少的,如果多的话来回拖甚是烦人,但是又想不出其他办法,如果你有更好的办法的话,请留言告知
csharpcode:[/b]
[code]//skillBtn
public UIButton Btn1;
public UIButton Btn2;
public UIButton Btn3;
public UIButton Btn4;
//skillbtn is down
bool is1Down;
bool is2Down;
bool is3Down;
bool is4Down;
//skillbtn is cooldown
bool is1CoolDown;
bool is2CoolDown;
bool is3CoolDown;
bool is4CoolDown;
void Start ()
{
bindingClick();
}
void Update ()
{
if(is1Down)
{
coldSkill(ref is1CoolDown,ref is1Down, Btn1.gameObject.transform.FindChild("Sprite").GetComponent<UISprite>()); //Sprite为黑色的遮罩,其是每个btn的子对象
}
if (is2Down)
{
coldSkill(ref is2CoolDown, ref is2Down, Btn2.gameObject.transform.FindChild("Sprite").GetComponent<UISprite>());
}
if (is3Down)
{
coldSkill(ref is3CoolDown, ref is3Down, Btn3.gameObject.transform.FindChild("Sprite").GetComponent<UISprite>());
}
if (is4Down)
{
coldSkill(ref is4CoolDown, ref is4Down, Btn4.gameObject.transform.FindChild("Sprite").GetComponent<UISprite>());
}
}
void bindingClick()
{
EventDelegate.Add(Btn1.onClick,delegate() { is1Down=true; });
EventDelegate.Add(Btn2.onClick,delegate() { is2Down=true; });
EventDelegate.Add(Btn3.onClick,delegate() { is3Down=true; });
EventDelegate.Add(Btn4.onClick, delegate() { is4Down = true; });
}
void coldSkill(ref bool isColding,ref bool isdown,UISprite spr)
{
if(!isColding)
{
isColding = true;
spr.fillAmount = 1;
}
if (isColding)
{
spr.fillAmount -= (1 / skillColdTime) * Time.deltaTime;
if (spr.fillAmount <= 0.01f)
{
spr.fillAmount = 0;
isColding = false;
isdown = false;
}
}
}
复制代码
作者:
hyui
时间:
2014-8-28 01:55
Thanks for this !
作者:
cgjch8
时间:
2014-8-28 09:24
thank you for sharing
作者:
Kadina
时间:
2014-8-29 07:25
thank you for sharing
欢迎光临 纳金网 (http://wwww.narkii.com/club/)
Powered by Discuz! X2.5