Blood bar or progress bar 2015-01-18 10:59:323 views
Using unity to do the blood bar or progress bar is really convenient, GUI ScrollBar can be easily implemented, plus lerp a blood bar or progress bar is completed.
JS Code
- Using Unityengine;
- Using System.Collections;
- Public class bloodbartest:monobehaviour {
- Public Guiskin Theskin;
- Public float bloodvalue = 0.0f;
- Private float tmpvalue;
- Private Rect Rctbloodbar;
- Private Rect Rctupbutton;
- Private Rect Rctdownbutton;
- Private bool OnOff;
- // Use this for initialization
- void Start () {
- Rctbloodbar = new Rect (20,20,20,200);
- Rctupbutton = new Rect (50,20,40,20);
- Rctdownbutton = new Rect (50,50,40,20);
- Tmpvalue = Bloodvalue;
- }
- void Ongui () {
- Gui.skin = Theskin;
- if (GUI. Button (Rctupbutton,"Add Blood")) {
- Tmpvalue = -1.0f;
- }
- if (GUI. Button (Rctdownbutton,"blood Loss")) {
- Tmpvalue + = 0.1f;
- }
- if (Bloodvalue > 0.0f) tmpvalue = 0.0f;
- if (Bloodvalue < -1.0f) Tmpvalue = -1.0f;
- Bloodvalue = Mathf.lerp (bloodvalue,tmpvalue,0.05f);
- //~ Debug.Log (Bloodvalue + "" + tmpvalue);
- Gui. Verticalscrollbar (Rctbloodbar, 1.0f, bloodvalue,0.0f, 1.0f,gui.skin.getstyle ("Verticalscrollbar"));
- }
- //Update is called once per frame
- void Update () {
- }
- }
This article is from "Dog planing Learning Net"
A blood bar or a progress bar.