Skip to content

Instantly share code, notes, and snippets.

@andydbc
Created November 5, 2024 23:40
Show Gist options
  • Save andydbc/a93f269410fd00b2857167eced74792b to your computer and use it in GitHub Desktop.
Save andydbc/a93f269410fd00b2857167eced74792b to your computer and use it in GitHub Desktop.
Retrieve content from a text file and assign it to a TextMesh component.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
[RequireComponent(typeof(TextMesh))]
[ExecuteInEditMode]
public class SetTextFromFile : MonoBehaviour
{
public TextAsset textFile;
[SerializeField]
private TMP_Text textMesh;
void Update()
{
if (textFile != null)
{
textMesh.text = textFile.text;
}
}
void OnValidate()
{
textMesh = GetComponent<TMP_Text>();
if (textFile != null)
{
textMesh.text = textFile.text;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment