Reputation: 400
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.
Upvotes: 7
Views: 8297
Reputation: 1
Go to Component->UI->Legacy->Text to insert textbox instead striving hard with TextMeshPro
Upvotes: -2
Reputation: 400
Found a solution. Used TextMeshProUGUI
instead of TextMeshPro
. Unsure of the details but it works.
Upvotes: 15