using UnityEngine;
using System.Collections; public class xt : MonoBehaviour
{ //红色血条
public Texture2D blood_red;
//黑色血条
public Texture2D blood_black;
//当前生命值
private int HP = ; void OnGUI()
{
if (GUILayout.RepeatButton("加血"))
{
//增加生命值
if (HP < )
{
HP++;
}
}
if (GUILayout.RepeatButton("减血"))
{
//减少生命值
if (HP > )
{
HP--;
}
}
//根据当前生命值计算红色血条显示的宽度
int blood_width = blood_red.width * HP / ;
//绘制黑色血条
GUI.DrawTexture(new Rect(, , blood_black.width, blood_black.height), blood_black);
//绘制红色血条
GUI.DrawTexture(new Rect(, , blood_width, blood_red.height), blood_red); }
}
资源下载