欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Unity使用Url加载网络图片

程序员文章站 2022-05-16 11:23:25
...
    IEnumerator DownLoadImgUserHead()
    {
        UnityWebRequest uwr = new UnityWebRequest("URL写在我这里", UnityWebRequest.kHttpVerbGET);
        uwr.downloadHandler = new DownloadHandlerTexture();
        yield return uwr.SendWebRequest();
        Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
        imgUserHead.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
    }
相关标签: Unity