Untitled

 avatar
unknown
csharp
2 years ago
1.0 kB
30
Indexable
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class SphereImageLoader : MonoBehaviour
{
    public Material sphereMaterial;
    public string imageUrl ;

     void Start()
    {
        StartCoroutine(DownloadAndApplyTextureCoroutine(imageUrl));
    }

    IEnumerator DownloadAndApplyTextureCoroutine(string url)
    {
        UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
        yield return www.SendWebRequest();

        if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
        {
            Debug.LogError("Error downloading texture: " + www.error);
        }
        else
        {
            Texture2D texture = DownloadHandlerTexture.GetContent(www);

            // Set the downloaded texture as the albedo
            if (sphereMaterial != null)
            {
                sphereMaterial.mainTexture = texture;

                
            }
        }
    }
}
Editor is loading...
Leave a Comment