Question by
sekmani52 · Sep 13, 2016 at 07:25 PM ·
camerascalebackground
the code fiixing the size camera and the background
Hi everyone I'm learning unity and i find the code for fix the size background foreach device you running the game but i try to understand the calculation in the code so i need some help to understand the calculation code and thanks
The code : using UnityEngine; using System.Collections;
public class BGscript : MonoBehaviour {
void Start () {
SpriteRenderer sr = GetComponent<SpriteRenderer>();
Vector3 tempScale = transform.localScale;
float width = sr.sprite.bounds.size.x;
float WorldHeight = Camera.main.orthographicSize * 2.0f;//why multiply the camera *2.0f
float WorldWidth = WorldHeight/ Screen.height * Screen.width;
tempScale.x = WorldWidth / width;
transform.localScale = tempScale;
}
}
Comment