유니티3D/예제
HPBar
당꿈응
2013. 8. 20. 13:47
using UnityEngine;
using System.Collections;
public class HPBar : MonoBehaviour {
public Texture ForegroundTexture;
public Texture BackgroundTexture;
public Texture2D DamageTexture; //use 2D UI and change color
void OnGUI() //draw picture method
{
Rect rect = new Rect(10,6,Screen.width/2-20,BackgroundTexture.height); //(x,y,width,height)
GUI.DrawTexture(rect,BackgroundTexture);
float hp = PlayerCtrl.hp;
rect.width *= hp;
GUI.color = DamageTexture.GetPixelBilinear(hp,0.5f); //read color value
GUI.DrawTexture(rect,ForegroundTexture);
GUI.color = Color.white;
}
}