I create a Sprite automatically from Texture2D.
How can I programmatically to change setting “Pixels To Units” of the Sprite?
This by default is set to 100, but I need set it to 1.
I create a Sprite automatically from Texture2D.
How can I programmatically to change setting “Pixels To Units” of the Sprite?
This by default is set to 100, but I need set it to 1.
TextureImporter.spritePixelsToUnits
I still don’t understand how it can help change the Sprite parameter in game. Small example could help me.
It’s an Editor AssetImporter class, you can’t use it at runtime.
Then go back to the original question: How can I programmatically to change setting “Pixels To Units” of the Sprite in game?
You can’t do that at runtime. Instead just change transform scale.
I found it! pixelsToUnits - this is the fourth parameter of the function Sprite.Create(). Thanks All!
Pixels To Units = spiteRenderer.sprite.textureRect.width / spiteRenderer.bounds.size.x (or from height / y
) at a scale = 1 for all dimensions!
So to receive this value = one command!!
And without creation new sprite.
good luck.