using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class DeletePoints : MonoBehaviour { private GameObject deleteId; public GameObject masterConnector; // Start is called before the first frame update void Start() { deleteId = null; } // Update is called once per frame void Update() { } public void setDeleteVisible(GameObject delete_id) { this.deleteId = delete_id; GameObject parent = GameObject.Find("Canvas"); Transform[] children = parent.GetComponentsInChildren(true); foreach(Transform ch in children) { if(ch.gameObject.name == "DeleteButton") { ch.gameObject.SetActive(true); } } } public void setDeleteNonVisible() { this.deleteId = null; GameObject parent = GameObject.Find("Canvas"); Transform[] children = parent.GetComponentsInChildren(true); foreach(Transform ch in children) { if(ch.gameObject.name == "DeleteButton") { ch.gameObject.SetActive(false); } } } public void deletePoints() { if(deleteId == null) { return; } string gn = masterConnector.GetComponent().GetGameNumber(); StartCoroutine(DeletePointsOnServer(gn)); } public IEnumerator DeletePointsOnServer(string thisGame) { string serverUrl = "https://smarthubs.media.tuwien.ac.at/api/delete_object"; string obj_id = deleteId.GetComponent().objectId.ToString(); // Create a Web Form WWWForm form = new WWWForm(); form.AddField("game", thisGame); form.AddField("oid", obj_id); using (UnityWebRequest www = UnityWebRequest.Post(serverUrl, form)) { yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); // PROMPT ERROR //errorPanel.SetActive(true); } else { Debug.Log("Form upload complete!"); } } } }