Displaying a Picture via Link

So, does unity have anyway to have a picture on the internet display through a link?
For example link a picture of someone’s Facebook profile pic.

You can use the WWW class to load textures

Here’s an example of exactly that:

So far I’ve been unsuccessful. No picture shows up. I am using a GUI box and passing the texture in if that makes a difference.

post your script

// I call this at Start()
IEnumerator webImage()
{
string url = “http://images.earthcam.com/ec_metros/ourcams/fridays.jpg”;
WWW www = new WWW(url);
yield return www.texture;
www.LoadImageIntoTexture(tempTex);
}

// In my OnGui()
void OnGUI()
// I’m leaving out bits of code like rRect assignment
GUI.Label(rRect, tempTex);
}

Thinking if over, not sure if this will be most efficient approach. What I’m needing to do is have a list of a persons friends on Facebook, but I’m not sure how fast linking to their profile pic will be.

For now though I just need to get this www image working.

I would suggest starting by using the example straight from the script reference, then put that texture into a gui label to make sure that works, then load a different texture… One thing at a time to see what’s not happening. Also, put in some “print” statements for debugging so you can follow what is / is not happening in there.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	private string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
	private WWW w;
	private Texture2D t2d;
	
	IEnumerator Start () {
		w = new WWW (url);
		yield return w;
		t2d = w.texture;
	}
	
	// Update is called once per frame
	void OnGUI () {
		GUILayout.Label (t2d);
	}
}

works fine

Works in the start, but not the function I made… what the hell…
Can it not be called anytime in the program or something?
Cause calling at the start won’t work for what I need to do.

sure it can

How? It won’t work for mine and I’m doing the exact same thing I’m doing in the function that I did in the start.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	private string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
	private WWW w;
	private Texture2D t2d;

	IEnumerator GetPic () {
		w = new WWW (url);
		yield return w;
		t2d = w.texture;
	}
	
	void OnGUI () {
		if (GUILayout.Button ("Get pic")) {
			StartCoroutine("GetPic");
		}
		GUILayout.Label (t2d);
	}
}

Do you call webImage directly, or do you make sure it’s within a StartCoroutine(webImage()); structure?

StartCoroutine was the problem. Didn’t know I needed to use that nor that there was a co routine function.

yep, Start is already a coroutine so if you want it somewhere else you need to start the coroutine

Yeah, Coroutines do some neat stuff under the hood, you need to let Unity know it’s a Coroutine (though some functions are automatically detected, like Start). Without it Coroutines will go until the first yield and never return.