unity3d-游戏实战突出重围,第二天 制作血条

时间:2021-10-09 16:27:55

unity3d-游戏实战突出重围,第二天 制作血条

 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); }
}

资源下载

http://pan.baidu.com/s/1dDEjy9b