UGUI_冻结技能键盘点击触发

1.在某一张image图上添加Button组件,使其具有点击触发事件的功能;

2.outline组件

3.SkillItem脚本

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 using UnityEngine.UI;
 5 
 6 public class SkillItem : MonoBehaviour {
 7     public float coldTime = 1;
 8     private Image filledImage;
 9     public KeyCode keycode;
10     private float timer = 0;
11     private bool isStartTimeer = false;
12     // Use this for initialization
13     void Start () {
14         filledImage = transform.Find("FilledImage").GetComponent<Image>();
15     }
16     
17     // Update is called once per frame
18     void Update () {
19         if (isStartTimeer)
20         {
21             timer += Time.deltaTime;
22         }
23         filledImage.fillAmount = (coldTime - timer) / coldTime;
24         if (timer >= coldTime)
25         {
26             filledImage.fillAmount = 0;
27             timer = 0;
28             isStartTimeer = false;
29         }
30 
31         if (Input.GetKeyDown(keycode))
32         {
33             isStartTimeer = true;
34         }
35     }
36     public void OnClick(){
37         isStartTimeer = true;
38     }
39 
40 }

Image类型为Filled;控制的参数为冻结图片中的组建Image中的fillAmount属性。

posted @ 2018-04-28 16:12  MR_L先生  阅读(177)  评论(0编辑  收藏  举报