• 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属性。

  • 相关阅读:
    jQuery应用 代码片段
    正则表达式大全
    js表单编程
    补充回顾
    Socket网路编程
    异常处理
    day18-2 反射详解
    day18-1 面向对象进阶
    day18-1 多态
    day17-2 继承
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/8968397.html
Copyright © 2020-2023  润新知