游戏CD
来源:互联网 发布:风速打印软件下载 编辑:程序博客网 时间:2024/06/07 07:21
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 (); }}
阅读全文
0 0
- 游戏CD
- cocos2d-x 游戏技能CD实现
- cocos2d-x游戏技能CD的实现
- ..CD..
- CD
- cd
- cd
- cd
- cd
- cd
- cd
- cd
- cd
- cd
- 2013金山西山居创意游戏程序挑战赛——初赛(1) C CD操作
- Cocos3.4 横版游戏制作-《KillBear》-技能及CD实现
- Unity制作游戏中技能使用后转CD的场景
- [小菜鸡学unity3D] 如何简单的制作游戏技能CD效果
- Appstore审核被拒-Guideline 2.3.3
- javascript高级程序设计笔记2-类属性设置
- XListView的使用
- 大神教你几招玩转Bootstrap框架技术
- 程序员,如何摆脱平庸?
- 游戏CD
- Spring 从实例读源码系列
- 自用的source insigth 配置文件
- C#学习笔记之——接口
- Mac 查看目录的方式
- 莫名其妙的问题
- ASCII字符显示例子
- 登陆界面
- JS复制网页内容自带版权信息