Simple script to render a ProgressBar


SUBMITTED BY: KaiMolan

DATE: Aug. 21, 2015, 9:05 p.m.

UPDATED: Aug. 21, 2015, 9:05 p.m.

FORMAT: C#

SIZE: 1.2 kB

HITS: 711

  1. /*
  2. * If you like my work, and found it useful
  3. * Please donate
  4. * Bitcoin Address: 1LdyAQHXdFVqzGzah45sGKhsQ8wDE6jyci
  5. * Good luck and enjoy.
  6. *
  7. */
  8. //goes with "ProgressBar Script for Unity (C#)" http://bitbin.it/sJiAXXCQ/
  9. using UnityEngine;
  10. namespace Assets.Scripts
  11. {
  12. public class ProgressBarRenderer :MonoBehaviour
  13. {
  14. private ProgressBar _bar;
  15. public void Init(ProgressBar bar)
  16. {
  17. _bar = bar;
  18. }
  19. public void OnGUI()
  20. {
  21. var oldColor = GUI.color;
  22. GUI.color = _bar.BackGroundColor;
  23. GUI.DrawTexture(new Rect(_bar.Position.x, _bar.Position.y, _bar.Size.x, _bar.Size.y), GameResources.Square);
  24. GUI.color = _bar.ForeGroundColor;
  25. GUI.DrawTexture(
  26. _bar.IsVertical
  27. ? new Rect(_bar.Position.x, _bar.Position.y, _bar.Size.x,_bar.Value * _bar.Size.y/_bar.MaxValue)
  28. : new Rect(_bar.Position.x, _bar.Position.y, _bar.Value*_bar.Size.x/_bar.MaxValue, _bar.Size.y),
  29. GameResources.Square);
  30. GUI.color = oldColor;
  31. }
  32. }
  33. }

comments powered by Disqus