- Home /
Assigning a texture to a renderer
Hi
no matter what I try I can't dynamically assign a texture from a file - this should be easy! Can anyone see why my code is not working?
And I'm looping through all renderers just because I figured assign the texture to ANY renderer in the scene - I don't care which one just show me the damn image!
Code assigned to the Canvas object:
public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
IEnumerator Start() {
Debug.Log( gameObject.name + ":: Start");
WWW www = new WWW(url);
yield return www;
Renderer[] allRenderers = GetComponentsInChildren<Renderer>();
foreach (Renderer thisRenderer in allRenderers) {
Debug.Log ( gameObject.name + ":: " + thisRenderer.name + ": " + thisRenderer.enabled);
thisRenderer.material.mainTexture = www.texture;
}
}
And by the way when I run this code I get 2 renderers found, both visible in the scene. Neither of them displays the loaded image. I've also tried loading an image from my local hard drive, in case its a cross domain issue (though its not because I can debug the code and browse the www object, an image is definitely loaded)
Please help! If I can't even get this working then I'll have to give up on Unity development and take up kitten juggling...
Ben
Your answer
Follow this Question
Related Questions
Load texture on disabled GameObject 1 Answer
www.texture results in black texture in Android 2 Answers
Image loaded with LoadImageIntoTexture gets inverted 0 Answers
Exception: not implemented? 2 Answers