- Home /
Question by
Stone-Legion · Nov 22, 2013 at 10:46 AM ·
spritesprite renderer
In Unity 4.3, how can I programatically create and change SpriteRenderer Sprite and Material with C#
For example, pretend I have a picture of a lemon png on a website that I'd like to load in game. I'd like to change the Sprite of the Sprite Renderer attached to a game object so that the new sprite is that of this lemon. I'm guessing that the texture might have to be downloaded first, then perhaps loaded with Resources.Load()?
public string url = "http://www.gettyicons.com/free-icons/138/fruits/png/256/lemon_256.png";
IEnumerator Start()
{
WWW www = new WWW(url);
yield return www;
renderer.material.SetTexture(0, www.texture);
}
Comment
Best Answer
Answer by Stone-Legion · Nov 23, 2013 at 01:20 AM
Answer can be found here: http://answers.unity3d.com/questions/581524/creating-sprite-in-code-using-textureimporter-with.html#answer-581551
Your answer
![](https://koobas.hobune.stream/wayback/20220613122500im_/https://answers.unity.com/themes/thub/images/avi.jpg)