Unity 分数增长
来源:互联网 发布:优化人员结构 编辑:程序博客网 时间:2024/06/01 07:54
Unity 分数增长
固定时间内增长
TweenTest.cs
using UnityEngine;using System;using System.Collections;public class TweenTest : MonoBehaviour{ private GameObject prefab; private UIButton btn; private UILabel scoreLabel; private float score; private float add; private GameObject addscore; private float StartValue = 0.0f; //开始的值 private float EndValue = 0.0f; //终点的值 private bool isStart = false; //是否开始 private bool isAdd = false; //是否增涨 public float speed = 0.0f; //速度 float addTime = 1.0f; // 增加所用的时间 void Awake() { // 预先创建好常用的得分Prefab prefab = (GameObject)Resources.Load("Prefabs/AddScore"); Application.targetFrameRate = 60;//此处限定60帧 } // Use this for initialization void Start() { btn = GameObject.Find("Button").GetComponent<UIButton>(); scoreLabel = GameObject.Find("Score").GetComponent<UILabel>(); scoreLabel.text = "" + score; // 设置按钮响应函数 EventDelegate.Add(btn.onClick, AddScore); } // Update is called once per frame void Update() { if (isStart) { if (isAdd) { StartValue += speed; if (StartValue > EndValue) { isStart = false; } } else { StartValue -= speed; if (StartValue < EndValue) { isStart = false; } } scoreLabel.text = (int)StartValue + ""; } } void AddScore() { isStart = true; isAdd = true; StartValue = EndValue; addscore = (GameObject)Instantiate(prefab, new Vector3(0, 0, 0), transform.rotation); UILabel addlabel = addscore.GetComponent<UILabel>(); System.Random random = new System.Random(); // 随机得分数 add = random.Next(500, 1000); Debug.Log("add = " + add); EndValue += add; speed = add / (Application.targetFrameRate * addTime); Debug.Log("speed = " + speed); if (speed <= 0) { speed = 1; } } }
固定速率增长
using UnityEngine;using System.Collections;public class PowerShow : MonoBehaviour { private float StartValue = 0; //开始的值 private int EndValue = 1000; //终点的值 private bool isStart = true; //是否开始 private bool isAdd = true; //是否增涨 public int Speed = 100; //速度 public UILabel Number_Label; void Update() { if(isStart) { if (isAdd) { StartValue += Speed * Time.deltaTime; if(StartValue>EndValue) { isStart = false; } } else { StartValue -= Speed * Time.deltaTime; if (StartValue < EndValue) { isStart = false; } } Number_Label.text = (int)StartValue + ""; } }}
0 0
- Unity 分数增长
- Unity给游戏添加倒计时和分数
- Unity 据手势滑动速度 控制能量条的增长
- 增长
- 【Unity】简单的分数排行榜功能实现(Web数据库)
- unity本地分数排行榜简单解决方案(Json)
- 分数
- 分数
- 分数
- 分数
- 分数
- 分数
- 分数
- 分数
- Unity修改分数的小技巧(UI篇)(Unity萌新的备忘录)
- unity使用AnimationCurve实现RPG中攻击与受伤时的分数的动态效果ScoreFlash
- 通过滑动手势控制摇杆移动并且通过移动的速度控制能量条的增长 Unity
- 外向型经济增长
- 设计模式之策略模式
- UI课程(标签/文本输入框/图片/按钮/代理)
- c 获取文件大小
- leetcode刷题,总结,记录,备忘 102
- Android中的动态加载机制
- Unity 分数增长
- Mac 升级之后找不到JDK,以及卸载从Oracle官网上面下载的JDK
- Spring(AbstractRoutingDataSource)实现动态数据源切换
- coreData数据库迁移
- 无线网络嗅探工具Kismet
- 数据结构概论
- error C2146: 语法错误 : 缺少“;”(在标识符“PVOID64”的前面)
- MVC、MVP、MVVM详解和区别
- LDA 线性判别分析(二)