using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public delegate void ScoreDelegate(int value);
public class UIAddScore : MonoBehaviour {
public Text score;
public Text scoreMax;
public Slider integral;
public Text nowIntegral;
public Text nextIntegral;
public Text levelIntegral;
private int maxScore = 0;
private int nowScore = 0;
private int level = 0;
private float tmpScore = 0;
private float maxValue = 100;
public static ScoreDelegate addScore;
public bool isResult = false;
private void Awake()
{
addScore += AddScore;
}
void Start () {
maxScore = GameData.Instance.GetInt("MaxScore", maxScore);
scoreMax.text = "最佳:" + GameData.Instance.GetInt("MaxScore", maxScore);
score.text = "" + Plate.score;
levelIntegral.text = "" + GameData.Instance.GetInt("level", level);
nowIntegral.text = "" + GameData.Instance.GetInt("nowIntegral", (int)tmpScore);
nextIntegral.text = "" + GameData.Instance.GetInt("nextIntegral", (int)maxValue);
integral.value = GameData.Instance.GetInt("nowIntegral", (int)tmpScore);
if (isResult)
{
nowScore = Plate.score;
StartCoroutine(ScoreCoroutine());
}
}
public void AddScore(int value)
{
score.text = "" + value;
nowScore = value;
GameData.Instance.SetInt("NowScore",value);
if (maxScore < value)
{
GameData.Instance.SetInt("MaxScore", value);
maxScore = value;
}
scoreMax.text = "最佳:" + GameData.Instance.GetInt("MaxScore", maxScore);
}
IEnumerator ScoreCoroutine() {
Debug.Log("ScoreCoroutine:" + nowScore);
while (tmpScore < nowScore)
{
integral.value = tmpScore;
if (tmpScore > maxValue)
{
maxValue *= 2.5f;
integral.maxValue = maxValue;
level++;
}
tmpScore += 0.5f;
nowIntegral.text = "" + (int)tmpScore;
nextIntegral.text = "" + (int)maxValue;
GameData.Instance.SetInt("nextIntegral", (int)maxValue);
GameData.Instance.SetInt("nowIntegral", (int)tmpScore);
GameData.Instance.SetInt("level",level);
yield return null;
}
//Debug.Log("ScoreCoroutine:" + tmpScore);
yield return null;
}
private void OnDestroy()
{
addScore -= AddScore;
}
}
UI显示分数
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 知识点: 1: 初、10:十、20:廿(niàn)、30:卅(sà)、40:卌(xì) Charts只有 Swi...
- 我们在平常制作2d小游戏的时候一般有一个分数的显示。对于用UGUI的童鞋来说,我们一般用text这个组件来实时...