0
\$\begingroup\$

So I have a square sprite (width == height) and I want to scale it so that both width and height are exactly one fifth of the width screen. To find the desired pixel width I do:
float desiredWidthPixels = Screen.width * 0.2f; float desiredHeightPixels = Screen.width * 0.2f;

How do I apply these values to the sprite?

\$\endgroup\$
1
\$\begingroup\$

You don't want to actually resize the sprite. What you want to do is resize the texture this sprite is being rendered on.

Once you get the texture you can call Texture2D.Resize(Screen.width * 0.2f, Screen.width * 0.2f)

If you're not sure which texture you are using, you can call Sprite.texture to get the texture used. If you wanted to, you could even do Sprite.texture.Resize(width, height).

http://docs.unity3d.com/ScriptReference/Sprite-texture.html http://docs.unity3d.com/ScriptReference/Texture2D.Resize.html

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.