Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Image is not loading from the server

Discussion in 'Scripting' started by schetty, May 21, 2014.

  1. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    Hi,

    I am trying to do pull the texture from the server and apply it to my gameobject.

    I have used the below code for this function:

    Code (csharp):
    1.  
    2.  
    3. private string url = "http://www.camelcitydispatch.com/wp-content/uploads/2013/08/Fire-Hands-Screensaver_1.jpg";
    4.  
    5.     private WWW www;
    6.  
    7.     public Material matl;
    8.  
    9.  
    10.     // Use this for initialization
    11.     IEnumerator Start () {
    12.  
    13.         www = new WWW (url);
    14.  
    15.         yield return www;
    16.  
    17.         matl.mainTexture = www.texture;
    18.  
    19.    
    20.     }
    21.  
    22.  
    this code working fine in the unity editor, but when i export it to the webplayer it is not working. Please tell me how to solve this and how to make it run.

    This is the image link:
    http://www.camelcitydispatch.com/wp-content/uploads/2013/08/Fire-Hands-Screensaver_1.jpg

    Thanks.
     
    Last edited: May 21, 2014
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Hi there, I think it could be restrictions because of security reason. The Unity webplayer expects a http served policy file named crossdomain.xml to be available on the domain you want to access with the WWW class... see here more information how it using http://docs.unity3d.com/Documentation/Manual/SecuritySandbox.html
     
  3. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    but if i use the javascript it is working, in c# only i is showing the problem.
     
  4. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Strange. Code the same in JS and C#?
     
  5. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    yes, both coding are same.
     
  6. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    So, use JS bro :cool:
    I have not the ghost of an idea why it's happend.
     
  7. darker9999

    darker9999

    Joined:
    May 23, 2012
    Posts:
    11
    Could it possibly be due to your mainTexture referencing the www.texture and when that coroutine ends the www.texture is removed from memory?
     
  8. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    no, it wont remove. it will be on the server itself.