- Home /
Trouble using WWW.LoadImageIntoTexture
Hi, I'm trying to download a picture from a URL and show it on a Panel. I came across this official script from Unity. I copied it dry and tried compiling it.
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
// Use this for initialization
void Start () {
// Create a texture in DXT1 format
renderer.material.mainTexture = new Texture2D(4, 4, TextureFormat.DXT1, false);
while(true) {
// Start a download of the given URL
var www = new WWW(url);
// wait until the download is done
yield www;
// assign the downloaded image to the main texture of the object
www.LoadImageIntoTexture(renderer.material.mainTexture);
}
}
// Update is called once per frame
void Update () {
}
}
I get the error "A local variable named 'www' is already defined in this scope". I can't seem to figure it out why. Any ideas? Thanks
Somewhere in same file (above or below) or maybe in dependency loaded you have www defined... You didn't show whole file though.
I updated my code, but I didnt leave out something important. It must have something to do with the dependencies then. Can you elaborate? Thanks
Errors here:
var url
- cannot be var. Should bestring url
.yield www;
- should beyield return www;
renderer variable is not defined. Did you intend to
$$anonymous$$eshRenderer renderer;
renderer=GetComponent< $$anonymous$$eshRenderer>();
?
Your answer
Follow this Question
Related Questions
How do you make an UI animation longer than one second? 3 Answers
How to change the selected image of a UI/Unlit/Transparent Material 0 Answers
How to get a random image url from google image search 0 Answers
Checking if Image Effects exist in the project 0 Answers
Does anyone have a solution for async image loading from url? 1 Answer