CircleSlider.cs 860 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class CircleSlider : MonoBehaviour
  6. {
  7. public bool b=true;
  8. public Image image;
  9. public float speed=0.5f;
  10. [SerializeField] bool doRotate = true;
  11. float time =0f;
  12. public Text progress;
  13. bool isClockwise = true;
  14. void Start()
  15. {
  16. image = GetComponent<Image>();
  17. }
  18. void Update()
  19. {
  20. if(b)
  21. {
  22. time += Time.deltaTime*speed;
  23. if(image.fillClockwise)
  24. {
  25. image.fillAmount = time;
  26. }
  27. else
  28. {
  29. image.fillAmount = 1 - time;
  30. }
  31. if(progress)
  32. {
  33. progress.text = (int)(image.fillAmount*100)+"%";
  34. }
  35. if(time>1)
  36. {
  37. if (doRotate)
  38. {
  39. image.fillClockwise = !image.fillClockwise;
  40. }
  41. time =0;
  42. }
  43. }
  44. }
  45. }