using UnityEngine; public class BgFit : MonoBehaviour { void Start() { SpriteRenderer sr = GetComponent(); if (sr == null) return; float width = sr.bounds.size.x; float height = sr.bounds.size.y; float worldHeight = Camera.main.orthographicSize * 2f; float worldWidth = worldHeight * Screen.width / Screen.height; transform.localScale = new Vector3( worldWidth / width, worldHeight / height, 1); } }