2013년 6월 12일 수요일

hp bar(1/2) - 기본

using UnityEngine;
using System.Collections;

public class ywplayerbar : MonoBehaviour {
public float maxBar = 100.0f;
public float justBar = 100.0f;
public float bgjustBar = 100.0f;
public float barLength;
public float bgbarLength;

// Use this for initialization
void Start () {
barLength = Screen.width /2;
bgbarLength = Screen.width /2;
}

// Update is called once per frame
void Update () {
AddjustCurrentBar(-3);

}

void OnGUI(){

GUI.Box(new Rect(10,10,barLength,20),justBar + "/"+ maxBar);
GUI.Box(new Rect(10,10,bgbarLength,20),bgjustBar + "/"+ maxBar);
}

public void AddjustCurrentBar(float adj){

justBar += adj * Time.deltaTime;

if(justBar<0)
justBar =0;
if(justBar>maxBar)
justBar=maxBar;
if(maxBar<1)
maxBar=1;


barLength = (Screen.width/2)*(justBar/(float)maxBar);


}


}

댓글 없음:

댓글 쓰기