CUI_RiseChildrenOverTime.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace CurvedUI
  4. {
  5. public class CUI_RiseChildrenOverTime : MonoBehaviour
  6. {
  7. float current = 0;
  8. public float Speed = 10;
  9. public float RiseBy = 50;
  10. // Use this for initialization
  11. void Start()
  12. {
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. current += Speed * Time.deltaTime;
  18. if (Mathf.RoundToInt(current) >= this.transform.childCount)
  19. current = 0;
  20. if (Mathf.RoundToInt(current) < 0)
  21. current = this.transform.childCount - 1;
  22. for (int i = 0; i < this.transform.childCount; i++)
  23. {
  24. if (Mathf.RoundToInt(current) == i)
  25. this.transform.GetChild(i).localPosition = this.transform.GetChild(i).localPosition.ModifyZ(-RiseBy);
  26. else
  27. this.transform.GetChild(i).localPosition = this.transform.GetChild(i).localPosition.ModifyZ(0);
  28. }
  29. }
  30. }
  31. }