- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
感觉这个方法适合技能较少的,如果多的话来回拖甚是烦人,但是又想不出其他办法,如果你有更好的办法的话,请留言告知
- 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;
- }
- }
- }
复制代码 |
|