zoukankan      html  css  js  c++  java
  • 技能CDDemo(点击鼠标左键实现技能界面旋转)

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    
    public class HealthController : MonoBehaviour {
    
        //当前对象是血条还是蓝条
        public bool isHealth = false;
        //虚拟轴,横轴,纵轴
        private float hor,ver;
        //血条的最大宽度
        private float healthMaxWidth = 470;
        //蓝条的最大宽度
        private float powerMaxWidth = 425;
        //当前的虚拟轴
        private float currentAxis;
        //当前的最大宽度
        private float currentMaxWidth;
        //RectTransform组件
        private RectTransform rectTr;
        //速度
        public float speed = 100;
        //血条文本
        public Text healthText;
        //蓝条文本
        public Text powerText;
        //血条蓝条的最大值
        public float healthMaxValue = 1000f;
        public float powerMaxValue = 500f;
        //当前的条的最大值
        private float currentMaxValue;
        //当前修改的文本显示框
        private Text currentText;
    
        void Start()
        {
            rectTr = GetComponent<RectTransform> ();
        }
    
        void Update()
        {
            hor = Input.GetAxis ("Horizontal");
            ver = Input.GetAxis ("Vertical");
            //如果是血条
            if (isHealth) {
                currentAxis = hor;
                currentMaxWidth = healthMaxWidth;
                currentText = healthText;
                currentMaxValue = healthMaxValue;
            }
            //如果是蓝条
            else {
                currentAxis = ver;
                currentMaxWidth = powerMaxWidth;
                currentText = powerText;
                currentMaxValue = powerMaxValue;
            }
            //根据用户的操作,计算当前条的宽度
            float newWidth = rectTr.sizeDelta.x +
                currentAxis * Time.deltaTime * speed;
            //限制宽度
            float realWidth = Mathf.Clamp (newWidth, 0, currentMaxWidth);
            //赋值到RectTransform
            rectTr.sizeDelta = new Vector2(realWidth,rectTr.sizeDelta.y);
            //计算当前数值
            float currentValue = (realWidth / currentMaxWidth) * currentMaxValue;
            //转整数操作
            currentValue = Mathf.Round (currentValue);
            //将数值信息显示到Text
            currentText.text = currentValue.ToString () + "/"
                + currentMaxValue.ToString ();
        }
    }

    技能组件界面  ImageType是Filled类型 数值是1与脚本里面初始值一致,脚本控制其数字从1-0减小调整白色画布填充,达到有技能冷却效果。

  • 相关阅读:
    实现一个简单的Http代理服务器
    微软的反向代理库YARP
    Elastic Search 基础——分析(Analysis)
    Elastic Seach基础—映射(Mapping)
    使用WebView2在.Net程序中集成Edge chromium
    Asp.net Core中实现自定义身份认证
    在Razor Pages的Url中增加扩展名后缀
    利用Aria2构造自己的下载工具(一)
    Mongodb中GUID的显示问题
    在Eclipse中使用MAT分析Android程序内存使用状况(转)
  • 原文地址:https://www.cnblogs.com/VR-1024/p/6011699.html
Copyright © 2011-2022 走看看