StarComp.cs 931 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Plugins.CxShine.UIUtil;
  5. using UnityEngine;
  6. public class StarComp : MonoBehaviour
  7. {
  8. public GameObject StarOnPrefab;
  9. public GameObject StarOffPrefab;
  10. private Transform _selfTr;
  11. private void Start()
  12. {
  13. if (_selfTr == null)
  14. _selfTr = gameObject.GetComponent<Transform>();
  15. setStar(3);
  16. }
  17. public void setStar(float value)
  18. {
  19. if (_selfTr == null)
  20. {
  21. _selfTr = gameObject.GetComponent<Transform>();
  22. }
  23. ContainerUtil.RemoveAllChild(this, _selfTr);
  24. for (int i = 0; i < 5; i++)
  25. {
  26. value -= 1;
  27. if (value >= 0)
  28. {
  29. Instantiate(StarOnPrefab, _selfTr, false);
  30. }
  31. else
  32. {
  33. Instantiate(StarOffPrefab, _selfTr, false);
  34. }
  35. }
  36. }
  37. }