22 lines
527 B
C#
22 lines
527 B
C#
using UnityEngine;
|
|
|
|
public class BgFit : MonoBehaviour
|
|
{
|
|
void Start()
|
|
{
|
|
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
|
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);
|
|
}
|
|
}
|