Instead of make 100 scripts for 100 different images im pulling from a URL, i want to make it be able to pull all 100 at a single load time and populate that inside of an index. Is this possible? This is my code as of now. This works fine for single image use, but i cant figure out multi use. Thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ImageLoader : MonoBehaviour
{
public Image image_1;
string url = "My.png";
void Start()
{
StartCoroutine(loadSpriteImageFromUrl(url));
}
IEnumerator loadSpriteImageFromUrl(string URL)
{
WWW www = new WWW(url);
while(!www.isDone)
{
Debug.Log("Download image in progress" + www.progress);
yield return null;
}
if(!string.IsNullOrEmpty(www.error))
{
Debug.Log("Download Failed");
}
else
{
Debug.Log("Download Success");
Texture2D texture = new Texture2D(1, 1);
texture.LoadImage(www.bytes);
texture.Apply();
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
image_1.sprite = sprite;
}
}
}