Advertisement
Splash6687

pastebin to text "RAW"

Apr 5th, 2024
1,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | Gaming | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.Networking;
  4.  
  5. public class PasteBinTextLoader : MonoBehaviour
  6. {
  7.     [SerializeField]
  8.     private string pasteBinRawLink = "YOUR_PASTEBIN_RAW_LINK_HERE";
  9.  
  10.     [SerializeField]
  11.     private GameObject[] targetGameObjects;
  12.  
  13.     private void Start()
  14.     {
  15.         StartCoroutine(LoadTextFromPasteBin());
  16.     }
  17.  
  18.     private IEnumerator LoadTextFromPasteBin()
  19.     {
  20.         UnityWebRequest www = UnityWebRequest.Get(pasteBinRawLink);
  21.         yield return www.SendWebRequest();
  22.  
  23.         if (www.result == UnityWebRequest.Result.Success)
  24.         {
  25.             string pasteBinText = www.downloadHandler.text;
  26.             foreach (GameObject obj in targetGameObjects)
  27.             {
  28.                 TextMesh textMesh = obj.GetComponent<TextMesh>();
  29.                 if (textMesh != null)
  30.                 {
  31.                     textMesh.text = pasteBinText;
  32.                 }
  33.                 else
  34.                 {
  35.                     Debug.LogWarning("TextMesh component not found on GameObject: " + obj.name);
  36.                 }
  37.             }
  38.         }
  39.         else
  40.         {
  41.             Debug.LogError("Failed to fetch PasteBin content: " + www.error);
  42.         }
  43.     }
  44. }
  45.  
Tags: #unityengine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement