我想使用我当前在 GUItext 中显示的信息创建一个健康栏。我想要的行为是让生命值随着时间的推移而减少(如倒数计时器),但每当玩家收集到一个物体时就会增加少量。
这是我当前的代码:
using UnityEngine;
using System.Collections;
public class TimeText : MonoBehaviour {
public GUIText timeText;
//countdown
public float timer = 99.00f;
// Update is called once per frame
void Update ()
{
timer -= Time.deltaTime*5;
timeText.text = "Health: " + timer.ToString("0");
}
}
这是我希望我的健康栏看起来的样子: