编辑:解决了。使用TextMeshProUGUI代替TextMeshPro。
背景:
我使用 TextMeshPro 来显示文本。我想通过脚本更改文本。问题是当我尝试更改它时会收到 NullReferenceException。
细节:
我的脚本:
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";
}
}
Run Code Online (Sandbox Code Playgroud)
代码与TextMeshPro API匹配,所以我不确定发生了什么。我正在使用 Unity 5.6.1f1。任何帮助是极大的赞赏。谢谢你。

错误:
所有这些错误都可以在这一行找到:
//ClassPractice.cpp
void tellStats(pick);
Run Code Online (Sandbox Code Playgroud)
哪个叫......
//Functions.h
void tellStats(string);
Run Code Online (Sandbox Code Playgroud)
这被定义为......
//Functions.cpp
void tellStats(string choice)
{
if (choice == "wizard")
{
cout << "These are the Wizard's stats:" << endl;
cout << "Max HP: 80\nSpeed: 7\nAttack: 10" << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我会收到这些错误.我不知道为什么int甚至涉及错误.在这些代码部分中,我没有看到任何涉及int的内容.我以为我正确使用'void'因为我不想用函数返回值.
在我的代码中我有这个:
int enemyNumber = numberType.at(0);
Run Code Online (Sandbox Code Playgroud)
numberType 是一个字符串.
第一个字符string numberType是'1'.但int enemyNumber在该任务之后变为48.
发生了什么,怎么让敌人的数字变成'1'?