UIBG.cs 716 B

12345678910111213141516171819202122232425262728
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class UIBG : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. }
  11. // Update is called once per frame
  12. void Update()
  13. {
  14. float bl = (float)Screen.width / this.GetComponent<RectTransform>().sizeDelta.x;
  15. float bl2 = (float)Screen.height / this.GetComponent<RectTransform>().sizeDelta.y;
  16. if (Screen.width > Screen.height)
  17. {
  18. this.transform.localScale = new Vector3(bl2,bl2,bl2);
  19. }else
  20. {
  21. this.transform.localScale = new Vector3(bl, bl, bl);
  22. }
  23. }
  24. }