UIBG.cs 794 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIBG : MonoBehaviour
  5. {
  6. // Start is called before the first frame update
  7. void Start()
  8. {
  9. StartCoroutine("check");
  10. }
  11. float w;
  12. float h;
  13. IEnumerator check()
  14. {
  15. while (true)
  16. {
  17. yield return new WaitForSeconds(1);
  18. w = Screen.width;
  19. h = Screen.height;
  20. if((float)((float)w/(float)h)<1920f/1080f)
  21. {
  22. this.GetComponent<RectTransform>().localScale = new Vector3(w, w * (1080f / 1920f), 1);
  23. }
  24. else
  25. {
  26. this.GetComponent<RectTransform>().localScale = new Vector3(h * (1920f / 1080f), h, 1);
  27. }
  28. }
  29. }
  30. }