I’m trying to embed a webpage into a UI panel but am stumped on a missing renderer component. I’m using this scipt:
using UnityEngine;
using System.Collections;
// Get the latest webcam shot from outside "Friday's" in Times Square
public class ExampleClass : MonoBehaviour {
public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
IEnumerator Start() {
// Start a download of the given URL
WWW www = new WWW(url);
// Wait for download to complete
yield return www;
// assign texture
Renderer renderer = GetComponent<Renderer>();
renderer.material.mainTexture = www.texture;
}
}
As this is in a UI Panel it has a Canvas Renderer component, but for some reason this is not a valid renderer component or it is not being accessed properly. Am I missingsomething? Or should I be using something else?
CanvasRenderer is not a Renderer, despite the name. You can see in the documentation that it inherits directly from Component.
Using the CanvasRenderer class is not the way to go, either. CanvasRenderer is a class that you’ll almost never want to actually use in script; it uses other UI components on the object (such as Image, Text, etc) to put together what it renders, and most of its functions are designed to be used by those components.
To display an image downloaded from the web, you’ll want to use the RawImage component, and you can set that component’s .mainTexture.
Thanks for the clarification, “A component that will render to the screen after all normal rendering has completed”. It makes sense now that I read it in light of your comment. I’m a little slow at times.