Assign (internet) JPG to sprite

I have this code and when I use “loadCard(x);” nothing happens (the php returns 0.jpeg if no card is found). I have a gameObject (Sprite) called “testcard” on the scene (with the spriterenderer).

    IEnumerator loadCard (int card_nr) {
        //Debug.Log("Loading card.");
        string url = root+"load_card.php?nr="+card_nr;
        WWW www = new WWW(url);
        //Debug.Log(url);
        yield return www;
        SpriteRenderer sr = GetComponent<SpriteRenderer>();
        sr.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
        GameObject card = GameObject.Find ("testcard");
        SpriteRenderer skin = card.GetComponent<SpriteRenderer>();
        skin = sr;

    }

What is the sr for? You give that one the sprite instead of the “testcard” in the scene. And at the end you’re simply overwriting that skin variable, which won’t actually change the component itself, only that local variable.

I guess this is what you are trying to do:

IEnumerator loadCard (int card_nr) {
    string url = root+"load_card.php?nr="+card_nr;
    WWW www = new WWW(url);
    yield return www;

    Sprite sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
  
    GameObject card = GameObject.Find ("testcard");
    SpriteRenderer skin = card.GetComponent<SpriteRenderer>();
    skin.sprite = sprite;
}