-
-
Save alec1o/5eff2358f8e7c88263b8ba5d205f4e7f to your computer and use it in GitHub Desktop.
Sample usage of UnityWebRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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