Created
November 5, 2024 23:40
-
-
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.
This file contains 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 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