技能CDDemo(点击鼠标左键实现技能界面旋转)
生活随笔
收集整理的這篇文章主要介紹了
技能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);//賦值到RectTransformrectTr.sizeDelta = new Vector2(realWidth,rectTr.sizeDelta.y);//計算當前數值float currentValue = (realWidth / currentMaxWidth) * currentMaxValue;//轉整數操作currentValue = Mathf.Round (currentValue);//將數值信息顯示到TextcurrentText.text = currentValue.ToString () + "/"+ currentMaxValue.ToString ();}
}
技能組件界面 ?ImageType是Filled類型 數值是1與腳本里面初始值一致,腳本控制其數字從1-0減小調整白色畫布填充,達到有技能冷卻效果。
轉載于:https://www.cnblogs.com/VR-1024/p/6011699.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的技能CDDemo(点击鼠标左键实现技能界面旋转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表单相关
- 下一篇: 基于吉日嘎拉的通用权限管理WebForm