A blood bar or a progress bar.

Source: Internet
Author: User

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
  1. Using Unityengine;
  2. Using System.Collections;
  3. Public class bloodbartest:monobehaviour {
  4. Public  Guiskin Theskin;
  5. Public   float bloodvalue = 0.0f;
  6. Private   float tmpvalue;
  7. Private  Rect Rctbloodbar;
  8. Private  Rect Rctupbutton;
  9. Private  Rect Rctdownbutton;
  10. Private  bool OnOff;
  11. // Use this for initialization   
  12. void Start () {
  13. Rctbloodbar = new Rect (20,20,20,200);
  14. Rctupbutton = new Rect (50,20,40,20);
  15. Rctdownbutton = new Rect (50,50,40,20);
  16. Tmpvalue = Bloodvalue;
  17. }
  18. void Ongui () {
  19. Gui.skin = Theskin;
  20. if (GUI. Button (Rctupbutton,"Add Blood")) {
  21. Tmpvalue = -1.0f;
  22. }
  23. if (GUI. Button (Rctdownbutton,"blood Loss")) {
  24. Tmpvalue + = 0.1f;
  25. }
  26. if  (Bloodvalue > 0.0f) tmpvalue = 0.0f;
  27. if  (Bloodvalue < -1.0f) Tmpvalue = -1.0f;
  28. Bloodvalue = Mathf.lerp (bloodvalue,tmpvalue,0.05f);
  29. //~ Debug.Log (Bloodvalue + "" + tmpvalue);   
  30. Gui.  Verticalscrollbar (Rctbloodbar, 1.0f, bloodvalue,0.0f, 1.0f,gui.skin.getstyle ("Verticalscrollbar"));
  31. }
  32. //Update is called once per frame   
  33. void Update () {
  34. }
  35. }

This article is from "Dog planing Learning Net"


A blood bar or a progress bar.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.