I’m working on an app in Unity. The problem is how to refresh the screen after you delete something from the database( PHP/MYSQL). Normally, I would destroy the objects then call the function that loads the data and displays the data(Coroutines) only after it destroys the data, it doesn’t start the coroutine as instructed.The script is on a prefab and I thought that if I simply copied the code from the other script, it would work. Alas, it did not.
public IEnumerator DeleteOilChange()
{
string ID = PlayerPrefs.GetString ("VehicleID");
WWWForm OilDeleteForm = new WWWForm ();
OilDeleteForm.AddField ("VehicleID", ID);
OilDeleteForm.AddField ("ServiceDate", OilServiceDate);
WWW OilDelete = new WWW ("http://localhost/CMVM/DeleteOilChange.php", OilDeleteForm);
yield return OilDelete;
Debug.Log (OilDelete.text);
DestroyObjects ("OilChange");
}
public IEnumerator GetAllOilChanges()
{
string ID = PlayerPrefs.GetString ("VehicleID");
WWWForm OilDataForm = new WWWForm ();
OilDataForm.AddField ("VehicleID", ID);
WWW OilData = new WWW ("http://localhost/CMVM/ViewOilChanges.php", OilDataForm);
yield return OilData;
Debug.Log (OilData.text);
string OD = OilData.text;
JSONArray VehicleArray = JSON.Parse (OD).AsArray;
ShowAllOilChanges (OD);
}
public void DestroyObjects(string tag)
{
GameObject[] Obj = GameObject.FindGameObjectsWithTag(tag);
if(Obj==null)
return;
else
{
Debug.Log(Obj.Length);
for(int i=0; i< Obj.Length; i++)
{
Destroy(Obj*);*
-
}*
-
Debug.Log(tag + "Objects Destroyed!");*
-
}*
-
StartCoroutine("GetAllOilChanges");*
-
}*
-
public void ShowAllOilChanges(string OD)*
-
{*
-
Debug.Log("Show All Vehicles!");*
-
var vehicles = JSON.Parse(OD);*
-
foreach(JSONNode v in vehicles)*
-
{*
-
GameObject vObj = Instantiate(OilChangePrefab);*
-
vObj.GetComponent<OilChangeScript> ().DisplayOilChanges (*
-
"ID: " + v["VehicleID"].Value,*
-
"ServiceDate: " + v["ServiceDate"].Value,*
-
"Location: " + v["ServiceLocation"].Value,*
-
"Mileage: " + v["Mileage"].Value,*
-
"Labor: " + v["Labor"].Value,*
-
"Oil Brand: " + v["OilBrand"].Value,*
-
"Oil Price: " + v["OilPrice"].Value,*
-
"Filter Brand: " + v["FilterBrand"].Value,*
-
"Filter Price: " + v["FilterPrice"].Value,*
-
"Purchase Place: " + v["PurchasePlace"].Value*
-
);*
-
//vObj.transform.SetParent(OilDisplayParent);*
-
}*
-
}*
When deleting, the script is on a prefab and it will not let me put the displayparent transform in the editor.