Friday, February 3, 2017

unity - Resize sprite to match camera width?


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

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...