Hello!
Over on the wiki there is an excellent script which is for Text Mesh Pro integration
I've been using this for a while however you have to add this as a component to each pair of text and TMPro objects you want to link. For instance, if you have a UI prefab like this:
You have to add the script five times.
I'm always keen to use less components if possible, so I was interested if it would be possible to just use a single instance of the script, but to still handle multiple text object pairs.
My modification:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using AC;
using UnityEngine.UI;
using TMPro;
[System.Serializable]
public class TextLinks
{
public Text textToCopyFrom;
public TextMeshProUGUI textMeshToCopyTo;
}
public class TextMeshPro_AC_New : MonoBehaviour
{
public TextLinks[] textLinks;
private void Update()
{
for (int i = 0; i < textLinks.Length; i++)
{
textLinks[i].textMeshToCopyTo.text = textLinks[i].textToCopyFrom.text;
}
}
}
The above allows you to have a single instance of the script and add as many text pairs as you like:
I guess the main upside is if you have a UI prefab with a lot of text & TMPro elements all the links can be seen in a single place.
Not sure if you'd consider that an improvement, but I thought I'd share regardless.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Of course, it's only now I've spotted that:
That's my new job this afternoon then!