Search Unity

how to resize the texture at runtime

Discussion in 'Scripting' started by UNITY3D_TEAM, Apr 15, 2013.

  1. UNITY3D_TEAM

    UNITY3D_TEAM

    Joined:
    Apr 23, 2012
    Posts:
    720
    how to re-size the texture at run time !.pls help me !regarding this


    for example:i have imported texture size of 200*200 when .while running game i need to change the size of the texture to 100*100 .

    give me suggestion to work on this


    thanks in advance
     
  2. wolfhunter777

    wolfhunter777

    Joined:
    Nov 3, 2011
    Posts:
    534
    How are you displaying your texture? As a game object or as a GUI?
     
  3. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    add your texture as a gameobject and at the runtime change the scale value of this texture object..
     
  4. UNITY3D_TEAM

    UNITY3D_TEAM

    Joined:
    Apr 23, 2012
    Posts:
    720
    im displaying my texture for game object.(part of a character body).!
     
  5. UNITY3D_TEAM

    UNITY3D_TEAM

    Joined:
    Apr 23, 2012
    Posts:
    720
    its possible to fit on that game object .what size that game object has
     
  6. wolfhunter777

    wolfhunter777

    Joined:
    Nov 3, 2011
    Posts:
    534
    If it's on a game object, just set the scale to be half of what it originally was.
    Code (csharp):
    1.  
    2. myScale = myObj.transform.localScale;
    3. myScale /= 2;
    4. myObj.transform.localScale = myScale;
    5.  
     
  7. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    I think you cannot change texture size at runtime.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  9. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    This works in Standalone but not in Webplayer - right?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Nope, it works in the webplayer.

    --Eric
     
    DizzyWascal and Expia like this.
  11. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Works fine now, thanks Eric!
     
  12. sbob322

    sbob322

    Joined:
    May 30, 2014
    Posts:
    12
    Had a similar issue loading images from a phone gallery into app for an app gallery and this was a life saver spent a week trying to find out how to do this before finally stumbling upon this. Thanks a ton.
     
  13. Expia

    Expia

    Joined:
    Oct 29, 2015
    Posts:
    18
    Someone give this man a medal.
    I am working on an app with 3 layers of different resolutions. It was easy enough to display them one on top of another centered into GUI elements which stretch them, but then I spent days to figure out how to crop one of them in accordance to the aim made with the 2 others.
    When I finaly found the correct solution this post came as a godsent for the final piece of the puzzle. I would have spent days and a lot of sanity to put all of this together correctly.
    Deepest appreciation.