FetchText

mail@pastecode.io avatar
unknown
csharp
6 months ago
667 B
1
Indexable
Never
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;

public class GetText : MonoBehaviour
{
    
    public string url;

    private void Start()
    {
        StartCoroutine(DownloadText());

    }

    public IEnumerator DownloadText()
    {
        using (UnityWebRequest uwr = UnityWebRequest.Get(url))
        {
            yield return uwr.SendWebRequest();

            if (string.IsNullOrEmpty(uwr.error))
            {
                this.GetComponent<TextMeshProUGUI>().text = uwr.downloadHandler.text;
            }
        }
    }
}
Leave a Comment