Search Unity

Getting image from link setting it to a box?

Discussion in 'Scripting' started by cCoding, Mar 29, 2013.

  1. cCoding

    cCoding

    Joined:
    Jul 3, 2012
    Posts:
    118
    I've been at this for 3 hours now and no success. I'm trying to get an image from my facebook page and set the box's texture as my picture. First I started getting constant stackflow exceptions. After I fixed that, I started getting null pointers. For some reason Unity just can't get the image. I feel as if i'm going in the wrong direction.

    Facebook graph links:

    https://graph.facebook.com/chernobyl360
    https://graph.facebook.com/chernobyl360/picture


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class fb_call : MonoBehaviour
    5. {
    6.  
    7.     public string fb_graph_call_url = "https://graph.facebook.com/"; //GENERAL CALL OF GRAPHS
    8.     public string fb_player_id; //PLAYERS ID
    9.     public string fb_pic_call = "/picture"; //PICTURE CALL
    10.     public string fb_id_call; // FB_GRAPHCALL_URL + FB_ID_TEST || CALLS PLAYER PAGE
    11.     public string fb_profile_picture;
    12.     public Texture2D fb_pic;
    13.     // Use this for initialization
    14.     void Start ()
    15.     {
    16.         fb_player_id = "chernobyl360";
    17.         fb_id_call = fb_graph_call_url + fb_player_id;
    18.         fb_profile_picture = fb_graph_call_url + fb_player_id + fb_pic_call;
    19.         FB_Profile_Pic ();
    20.     }
    21.  
    22.     IEnumerator FB_Profile_Pic ()
    23.     {
    24.         WWW pic_url = new WWW (fb_profile_picture);
    25.         yield return pic_url;
    26.        
    27.         pic_url.LoadImageIntoTexture (fb_pic);
    28.     }
    29.    
    30.         void OnGUI ()
    31.     {
    32.         //GUI.Box(new Rect(0, 0, 50, 50), facebook_caller.twit_pic, social_style);
    33.        
    34.         GUI.Box (new Rect (0, 0, 50, 50), fb_pic);
    35.  
    36.     }
    37.     // Update is called once per frame
    38.     void Update ()
    39.     {
    40.  
    41.     }
    42. }
    43.  
     
    Last edited: Mar 29, 2013
  2. cCoding

    cCoding

    Joined:
    Jul 3, 2012
    Posts:
    118
    Any help would be greatly appreciated. i'll give this another shot on my own but I feel that i'm not either going in the right direction or i'm completely not understanding how to WWW.texture works.