hey guys . how can i improve this script with one InputField and array of gameobjects that saves the previous texture?
{
public InputField texUrlInput0;
public GameObject panel0;
public InputField texUrlInput1;
public GameObject panel1;
public void setTextureFromWeb()
{
string textureurl = texUrlInput0.text;
StartCoroutine(DownloadTexture(textureurl));
}
IEnumerator DownloadTexture(string textureurl)
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture(textureurl);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log(request.error);
}
else
{
Texture texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
panel0.GetComponent<Renderer>().material.mainTexture = texture;
}
}
public void setTextureFromWeb1()
{
string textureurl = texUrlInput1.text;
StartCoroutine(DownloadTexture1(textureurl));
}
IEnumerator DownloadTexture1(string textureurl)
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture(textureurl);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log(request.error);
}
else
{
Texture texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
panel1.GetComponent<Renderer>().material.mainTexture = texture;
}
}
}