HeightFixer.cs 618 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class HeightFixer : MonoBehaviour {
  5. public void FixHeight()
  6. {
  7. ((RectTransform)transform).SetHeight(TotalHeight);
  8. }
  9. public float TotalHeight
  10. {
  11. get
  12. {
  13. float totalChildrenHeight = 0.0f;
  14. foreach (RectTransform tform in transform.GetChilds())
  15. {
  16. totalChildrenHeight += tform.GetHeight();
  17. }
  18. return totalChildrenHeight + 15;
  19. }
  20. }
  21. //private void Update()
  22. //{
  23. // FixHeight();
  24. //}
  25. }