public IEnumerator DataInstantiate(string type, string itemsOnServerPath, string prefabPath) { int numItems; string itemsFromBD = ""; JsonData jsonvale; authorization = AuxFunctions.Authenticate("MLORETO", "Marco.2017"); UnityWebRequest www = UnityWebRequest.Get(itemsOnServerPath); www.SetRequestHeader("AUTHORIZATION", authorization); yield return(www.Send()); DestroyEmpty(); if (www.error == null) { itemsFromBD = www.downloadHandler.text; jsonvale = JsonMapper.ToObject(itemsFromBD); numItems = jsonvale["d"]["results"].Count; GameObject prefabInstance = Resources.Load(prefabPath) as GameObject; if (numItems > 0) { for (int i = 0; i < numItems; i++) { GameObject DataInstance = Instantiate(prefabInstance, GameObject.Find("Grid").transform) as GameObject; DataInstance.name = type + i; switch (type) { case "empresa": DataInstance.transform.Find("Fondo").transform.Find("Titulo").GetComponent <Text>().text = jsonvale["d"]["results"][i]["NAME"].ToString(); DataInstance.GetComponent <EmpresaElementScript>().empresaID = jsonvale["d"]["results"][i]["PARTNERSHIPID"].ToString(); break; case "granja": DataInstance.transform.Find("Fondo").transform.Find("Titulo").GetComponent <Text>().text = jsonvale["d"]["results"][i]["FARMNAME"].ToString(); DataInstance.GetComponent <GranjaElementScript>().granjaID = jsonvale["d"]["results"][i]["BROILERSFARMID"].ToString(); break; case "nucleo": DataInstance.transform.Find("Fondo").transform.Find("Titulo").GetComponent <Text>().text = jsonvale["d"]["results"][i]["NAME"].ToString(); DataInstance.GetComponent <NucleoElementScript>().nucleoID = jsonvale["d"]["results"][i]["CENTERID"].ToString(); break; case "galpon": DataInstance.GetComponent <GalponElementScript>().id = i; DataInstance.GetComponent <GalponElementScript>().galponID = jsonvale["d"]["results"][i]["SHEDCODE"].ToString(); DataInstance.transform.Find("QR").GetComponent <RawImage>().texture = AuxFunctions.generateQR(i.ToString()); //DataInstance.GetComponent<GalponElementScript>().Initialize(); break; } } } else { GameObject DataInstance = Instantiate(prefabInstance, GameObject.Find("Grid").transform) as GameObject; DataInstance.transform.Find("Fondo").transform.Find("Titulo").GetComponent <Text>().text = "Vacio"; } readyInstantiate = true; } else { Debug.Log("ERROR: " + www.error); } }