This script will scale the background for different screen resolutions.
void Start()
{
SpriteRenderer sr = GetComponent<SpriteRenderer>();
transform.localScale = new Vector3(1, 1, 1); //reset scale
float Height = sr.sprite.bounds.size.y;
float Width = sr.sprite.bounds.size.x;
float WorldHeight = Camera.main.orthographicSize * 2f;
float WorldWidth = WorldHeight / Screen.height * Screen.width;
Vector3 tempscale = transform.localScale;
tempscale.x = WorldWidth / Width + 0.1f;
tempscale.y = WorldHeight / Height + 0.1f;
transform.localScale = tempscale;
}
Comments
Post a Comment