0
\$\begingroup\$

I have written a script that should make sure the aspect ratio of my image stays the same when i import it into unity.
This is the script:

public class PostprocessImages : AssetPostprocessor
{
    void OnPostprocessTexture(Texture2D texture)
    {
        TextureImporter textureImporter = (TextureImporter)assetImporter;
        textureImporter.npotScale = TextureImporterNPOTScale.None;
        textureImporter.mipmapEnabled = false;
    }
}

the script is located in the Editor folder in Assets. But when i import an image i get the following result:

enter image description here

this is definitly not what i am looking for.
It should look like this:

enter image description here

But when i just go to the inspector of the imported image and change a random setting and hit apply the texture does get the proper aspect ratio back. And the settings i modified in the code. Are correct when i inspect the image. But the image doesnt have the right aspect ration..
See image below:

enter image description here

how would i go about making the image have the right aspect ratio, right from the getgo (when i import it). Because i dont want to do it manual since i have to import hundereds of images.

Let me know if something is unclear so i can clarify.

\$\endgroup\$

Your Answer

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

Browse other questions tagged or ask your own question.