Slide 15
Slide 15 text
public class TouchAction : MonoBehaviour, IInputClickHandler
{
string fb_url = “https://xxxxxxxx.firebaseio.com/xxxxxxxxxx/word.json”;
public void OnInputClicked(InputClickedEventData eventData)
{
StartCoroutine(Put(fb_url, “\"ண\""));
}
public IEnumerator Put(string url, string jsonStr)
{
var request = new UnityWebRequest();
request.url = url;
byte[] body = Encoding.UTF8.GetBytes(jsonStr);
request.uploadHandler = new UploadHandlerRaw(body);
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json; charset=UTF-8");
request.method = UnityWebRequest.kHttpVerbPUT;
yield return request.Send();
if (!request.isNetworkError)
{
if (request.responseCode == 200)
{
Debug.Log("success");
Debug.Log(request.downloadHandler.text);
}
else
{
Debug.Log("failed");
}
}
}
}