NGUI health bar, vital bar
Unity3D/NGUI / 2012. 10. 25. 15:01
http://www.youtube.com/watch?v=h0x5196mWlk
using UnityEngine;
using System.Collections;
public class VitalBar : MonoBehaviour {
private UISlider _slider;
private float _maxWidth;
public float health = 1f;
void Awake() {
_slider = GetComponent<UISlider>();
if(_slider==null)
{
Debug.LogError("Could not find the UISlider Component!");
return;
}
_maxWidth = _slider.foreground.localScale.x;
Debug.Log(_maxWidth);
}
void Update(){
UpdateDisplay(health);
}
public void UpdateDisplay(float x){
_slider.foreground.localScale = new Vector3(_maxWidth*x,_slider.foreground.localScale.y, _slider.foreground.localScale.z);
}
}
반응형
'Unity3D > NGUI' 카테고리의 다른 글
NGUI - Sticky Floating Text (0) | 2012.10.28 |
---|---|
NGUI: HUD Text (0) | 2012.10.26 |
NGUI와 NGUI: HUD Text 패키지 임포트 시 에러 문제.. (0) | 2012.10.25 |
Button Cooldown effect (0) | 2012.10.16 |
NGUI 링크 모음 (0) | 2012.10.16 |