現在 GUI テキストに表示している情報を使用して、ヘルス バーを作成したいと考えています。私が望む動作は、ヘルスが時間の経過とともに (カウントダウン タイマーのように) 減少し、プレイヤーがオブジェクトを収集するたびに少しずつ増加することです。
これが私の現在のコードです:
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");
}
}
ヘルスバーを次のように表示します。