- Home /
I want a get images from a local server and display on a screen using a button to change the images in my game. i learnt you can use www class but i don't understand the code
I want a get images from a local server and display on a screen using a button to change the images in my game. i learnt you can use www class but i don't understand the code. Please can you please comment your code properly so that i can understand what each word or line in the code does. Thank you
Answer by ryandotdee · Feb 12, 2015 at 01:29 PM
Documentation is pretty good for WWW, from what you have described you would need the LoadImageIntoTexture method
http://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html
the documentation is well commented, so there is no point me re writing the same comments, give that a shot and let us know how you get on
i am using c# not js, and how does the code knows which plane to render it on? And thanks so much for replying. I am kind of new, so please bear with me.
You can switch the displayed script language in the top right corner (C#, JS and Boo). Just apply the texture to any renderer you wish to.
If you look in the top right corner of the screen on the documentation pages, you can change it to display c# ( althoug it looks broken on that page)
am at work atm so cant test this, but it would be something along these lines
string url = "http://www.site.com/image.png";
WWW imageURLWWW = new WWW(url);
yield return imageURLWWW;
if(imageURLWWW.texture != null) {
Sprite sprite = new Sprite();
sprite = Sprite.Create(imageURLWWW.texture, new Rect(0, 0, 400, 400), Vector2.zero);
//Assign the sprite to the Image Component
GetComponent<Image>().sprite = sprite;
}
sorry to disturb you but regardless of what i select, whether C# or JS or BOO, the code does not change.