I'm trying to resize my small background sprite to match the screen width of the user's device.
This is what I'm trying
// Use this for initialization
void Start () {
// Set filterMode
SpriteRenderer sr = (SpriteRenderer) GetComponent("Renderer");
sr.sprite.texture.filterMode = FilterMode.Point;
// Get scaling
float multiplier = Camera.main.rect.width / sr.sprite.bounds.size.x;
// Scale
transform.localScale = localScale * multiplier;
}
It seems there is a problem with the measure I get from the Camera width, I also tried Screen.width but it seems it returns the value in pixels.
No comments:
Post a Comment