EDIT: Solved. Used TextMeshProUGUI
instead of TextMeshPro
.
Background:
I'm using TextMeshPro to display text. I want to change the text via a script. The problem is I get a NullReferenceException when I attempt to change it.
Details:
My script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class UI_speed : MonoBehaviour {
TextMeshPro textmeshPro;
void Start () {
textmeshPro = GetComponent<TextMeshPro>();
textmeshPro.text = "test";
}
}
The code matches the TextMeshPro API so I'm not sure what's going on. I'm using Unity 5.6.1f1. Any help is greatly appreciated. Thank you.
Found a solution. Used TextMeshProUGUI
instead of TextMeshPro
. Unsure of the details but it works.
Try using
textmeshPro = GetComponentInChildren<TextMeshPro>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With