Search Unity

Set mainTexture with scale to fit for a Game Object

Discussion in 'Editor & General Support' started by fabiensen, Nov 23, 2014.

  1. fabiensen

    fabiensen

    Joined:
    Nov 23, 2014
    Posts:
    2
    Hi all,

    long story short: I download many images from a web service, each one having different size.
    Now, I have the same number of game objects (created dynamically at runtime according to the response of the web service, however the panels are all of the same size) representing a wall. I try to set the images as mainTexture of the walls (simulating frames on a wall). So, I do like that:

    go.renderer.material.mainTexture = img;

    Is there any way to set the mainTexture images at the center of the panel, keeping its ratio, and possibly their size? I'd need a sort of UIImage behavior in iOS, when you have a UIImageView and set this to scale the image to fit. By now, I have all the images at the same size (that is, the same size of the game object) in the scale to fill mode (so, only a part of the image is visible or it repeats itself if smaller).

    Anybody could help me?

    Thanks!
    Fabio
     
    karim1king likes this.