www.texture is Texture2D, create GO with RawImage component and set its texture;
RawImage ri = new GameObject(“Image”).AddComponent();
ri.texture = www.texture;
Unfortunately this doesn’t work it seems. Unity doesn’t know a componente called RawImage. Unknown Identifier in JS, and type or namespace could not be found in C#
Okay, i think i have misunderstood what you tried to tell me. So i tried the same with the Raw Image component for UI now. With the same result. This time Unity moans about that it cannot convert to raw image instead of texture 2d:
Curious enough the manual states:
This sounds to me that this should work:
var myrawimage:UI.RawImage;
…
myrawimage=www.texture;
I’m a bit confused, do you understand that Texture2D and RawImage/Image are completely different types?
And again in my code I set myrawimage_.texture_ = www.texture and not just instance of RawImage directly.
Yes i understand that those two are two different types. Guess why i search for a method to convert texture2D to something different that can be read by the UI component.
Problem is your code gives me error. Unity does not know a component called RawImage. And myrawimage has no type called texture. It has raw texture or sprite.
I’m completely confused ^^
EDIT, now i get this part at least. Man, i’m blind today. I need to access the texture component of the script. So easy …
I know it’s an old thread, but thought I would post this anyway in case it helps anyone. I have been using this way and it works just fine loading URL’s into a sprite.
private string url = "http://www.somewebsite.com/images/someImage.jpg";
public GameObject myImageGO; // This is the GameObject with the Image Component on it
//In Start or where ever are going to call to get and load the image use:
void Start()
{
StartCoroutine(LoadImage(url));
}
private IEnumerator LoadImage(string loadedURL)
{
Texture2D temp = new Texture2D(0,0);
WWW www = new WWW(loadedURL);
yield return www;
temp = www.texture;
Sprite sprite = Sprite.Create(temp, new Rect(0,0,temp.width, temp.height), new Vector2(0.5f,0.5f));
Transform thumb = myImageGO.transform;
thumb.GetComponent<Image>().sprite = sprite;
}