Untitled

mail@pastecode.io avatar
unknown
csharp
7 months ago
1.0 kB
27
Indexable
Never
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;

                
            }
        }
    }
}
Leave a Comment