Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Problem with resize sprite or texture 2d

Discussion in '2D' started by frigatplaygames, Apr 30, 2022.

  1. frigatplaygames

    frigatplaygames

    Joined:
    Dec 3, 2021
    Posts:
    3
    Code (CSharp):
    1. Texture2D SpriteTexture = LoadTexture(FilePath);
    2. Sprite NewSprite = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.width), new Vector2(0, 0), 100.0f, 0, SpriteMeshType.FullRect);
    The first line calls the method which, according to the path, finds the image and returns it as a texture. In the second line I create a sprite using the texture.

    However, my image has a resolution of 250x250 px and I want to reduce it to 150x150.

    I have tried doing resize texture or changing something in the sprite creation parameters. In the end the image either gets larger or disappears altogether. What are the options for solving my query?
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you will have to resize the image in your image editor program, theres no feature to resize images in unity
     
  3. frigatplaygames

    frigatplaygames

    Joined:
    Dec 3, 2021
    Posts:
    3
    Wouldn't shrinking a sprite also shrink the texture with which the sprite was created?
    Or is there nothing that could have been changed during the texture from image generation phase?
     
  4. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you can look up something called "render textures" and try to create a new texture using that but it will involve extra coding steps, it wont be as easy as just choosing the new size and it just scales like you were using an image editor like photoshop