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;

}

}


'유니티3D > 예제' 카테고리의 다른 글

All Script in ThirdPersonShooingGame  (0) 2013.08.23
plane size 동적할당  (0) 2013.08.21
시계바  (0) 2013.08.20
PaddleGame  (0) 2013.08.15
MonsterCtrl.cs  (0) 2013.08.12

+ Recent posts