SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();

if (spriteRenderer == null)
	return;

gameObject.transform.localScale = new Vector3(1, 1, 1);

float _width = spriteRenderer.bounds.size.x;
float _height = spriteRenderer.bounds.size.y;

float worldScreenHeight = (float)(Camera.main.orthographicSize * 2.0);
float worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;


gameObject.transform.localScale = new Vector3(worldScreenWidth / _width, worldScreenHeight/_height,1);

출처: answers.unity.com/questions/620699/scaling-my-background-sprite-to-fill-screen-2d-1.html

+ Recent posts