using System.Collections; using System.Collections.Generic; using UnityEngine; [ExecuteInEditMode] public class UIBG : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { float bl = (float)Screen.width / this.GetComponent<RectTransform>().sizeDelta.x; float bl2 = (float)Screen.height / this.GetComponent<RectTransform>().sizeDelta.y; if (Screen.width > Screen.height) { this.transform.localScale = new Vector3(bl2,bl2,bl2); }else { this.transform.localScale = new Vector3(bl, bl, bl); } } }