Author Topic: Load texture in UISprite  (Read 3039 times)

foksot

  • Guest
Load texture in UISprite
« on: July 14, 2013, 04:00:17 PM »
Hello,

I want to load an image from a web location and have it as a texture to an UISprite. I figured how to get that image from the website using the WWW form but I cant show it to the UISPrite.

Any help appreciated

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load texture in UISprite
« Reply #1 on: July 14, 2013, 07:17:59 PM »
UISprite is for textures stored in an atlas. Downloaded texture won't be in an atlas. Use UITexture to display it instead of UISprite.

broken

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 140
    • View Profile
Re: Load texture in UISprite
« Reply #2 on: July 15, 2013, 12:52:33 AM »
It would be great to have only one common class UISprite which would contain a functional for the current UISprite and for current UITexture.

foksot

  • Guest
Re: Load texture in UISprite
« Reply #3 on: July 15, 2013, 05:34:30 AM »
UISprite is for textures stored in an atlas. Downloaded texture won't be in an atlas. Use UITexture to display it instead of UISprite.

So how I can do that ? can you give me a simple example because I am a newbie....

I have to add a new NGUI object in my scene that is UITexture and then in my scripts what I have to write to display it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Load texture in UISprite
« Reply #4 on: July 15, 2013, 06:56:42 AM »
Yes, add a UITexture instead of a UISprite to where you want it to be displayed. Download the texture like you normally would using WWW (consult Unity docs), then do something like this:

GetComponent<UITexture>().mainTexture = yourDownloadedTexture;

foksot

  • Guest
Re: Load texture in UISprite
« Reply #5 on: July 15, 2013, 10:14:39 AM »
Thanks a lot I made it :)