How to load an image from URL with Unity?

后端 未结 6 1787
感情败类
感情败类 2020-12-10 06:05

Please save me from going crazy.

No matter how many times I google, I always end up with (usually deprecated) versions of the following code:

IEnumer         


        
6条回答
  •  半阙折子戏
    2020-12-10 06:47

    public void OnStart()
    {
        StartCoroutine(setImage("http://drive.google.com/myimage.jpg")); 
    }
    
    IEnumerator setImage(string url) 
    {
        Texture2D texture = null;
        WWW www = new WWW(url);
        yield return www;
    
        Debug.Log("Why on earh is this never called?");
        texture = WWW.texture;
        //end show Image in texture 2D
    }
    

提交回复
热议问题