how can i change this script with 1 InputField and array of gameobjects?

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;
        }
    }

}

Hi hesamkahn, here is a version that uses an array. I wasn’t sure what you wanted to do if someone clicked it again before it finished so I just made it insist that you wait - this way you’d never end up with panels where the textures failed to download. If you want to fire off lots and any that fail result in blank panels, then instead you just want to cache the panel index in the DownloadTexture function and increase it straight away (you can then also do away with the downloading bool).

using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public class Panels : MonoBehaviour {

  public InputField texUrlInput;
  public GameObject[] panels;
  private int panelIndex = 0;
  private bool downloading = false;

  public void setTextureFromWeb() {
    string textureurl = texUrlInput.text;
    if (downloading) {
      Debug.Log("Already downloading, please wait until it completes or errors");
    } else {
      // Catch to make sure we've not used up all our panels.
      if (panelIndex < panels.Length) {
        StartCoroutine(DownloadTexture(textureurl));
      } else {
        Debug.Log("Trying to download more textures than panels, oops.");
      }
    }
  }

  IEnumerator DownloadTexture(string textureurl) {
    downloading = true;
    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;
      // Success, increment the panel index so next time it goes into the next one.
      panels[panelIndex++].GetComponent<Renderer>().material.mainTexture = texture;
    }
    // Reset our downloading variable.
    downloading = false;
  }
}