Skip to content

Instantly share code, notes, and snippets.

@alec1o
Forked from emoacht/UnityWebRequestUsage.cs
Last active July 10, 2023 06:28
Show Gist options
  • Select an option

  • Save alec1o/5eff2358f8e7c88263b8ba5d205f4e7f to your computer and use it in GitHub Desktop.

Select an option

Save alec1o/5eff2358f8e7c88263b8ba5d205f4e7f to your computer and use it in GitHub Desktop.
Sample usage of UnityWebRequest
using System.Collections;
using UnityEngine;
using UnityEngine.Experimental.Networking;
public class UnityWebRequestUsage : MonoBehaviour
{
void Start()
{
StartCoroutine(GetText());
}
IEnumerator GetText()
{
using (UnityWebRequest request = UnityWebRequest.Get("http://unity3d.com/"))
{
request.downloadHanlder = new DownloadHandlerBuffer();
yield return request.Send();
if (request.isError) // Error
{
Debug.Log(request.error);
}
else // Success
{
Debug.Log(request.downloadHandler.text);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment