'Error when referencing TextMeshPro in Script
I'm switching from Text(legacy) to TextMeshPro in Unity. When switching I've tried using
public TextMeshProUGUI ScoreText;
but get this error: Assets\scrips\gamemanager.cs(17,9): error CS0246: The type or namespace name 'TextMeshProUGUI' could not be found (are you missing a using directive or an assembly reference?).
Script:
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class gamemanager : MonoBehaviour
{
public TextMeshProUGUI ScoreText;
int scoreText = 0;
string ScoreText_string;
public void NextLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void plusTen()
{
scoreText += 10;
}
void Update()
{
ScoreText_string = scoreText.ToString();
ScoreText.text = ScoreText_string;
}
}
Note: editor version 2021.3.1f
Solution 1:[1]
TextMeshProUGUI class resides in TMPro namespace. You must have to use the namespace TMPro with using statement or simply do
public TMPro.TextMeshProUGUI ScoreText;
Also, you must have to import the TextMeshPro package in your project as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Digvijaysinh Gohil |
