C# 如何将字符串播放器引用与TextMeshPro一起使用?
我一直在遵循一个使用playerprefs保存玩家名称的教程。 我让它工作正常的文本,但不是与TextMeshPro。有没有办法编辑代码,这样我就可以在脚本中使用TextMeshPro 第一稿C# 如何将字符串播放器引用与TextMeshPro一起使用?,c#,unity3d,text,C#,Unity3d,Text,我一直在遵循一个使用playerprefs保存玩家名称的教程。 我让它工作正常的文本,但不是与TextMeshPro。有没有办法编辑代码,这样我就可以在脚本中使用TextMeshPro 第一稿 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SaveName : MonoBehaviour { public
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveName : MonoBehaviour
{
public InputField textBox;
public void ClickSaveButton()
{
PlayerPrefs.SetString("name", textBox.text);
Debug.Log("Your name is " + PlayerPrefs.GetString("name"));
}
}
第二稿
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NameScene : MonoBehaviour
{
public Text NameBox;
void Start()
{
NameBox.text = PlayerPrefs.GetString("name");
}
// Update is called once per frame
void Update()
{
}
}
将TextMeshPro导入脚本,而不是
公共文本名称框代码>使用公共TMP_文本名称框代码>您有什么问题?使用TextMeshPro安装文本时出现了什么错误?TextmeshPro具有所有文本类功能以及更多功能。您可以通过textmashpro.text从textmashpro获取文本,这是相同的。只需使用TMPro;添加即可。此外,如果它是ui对象,您应该使用TextMeshProUGUI而不是Text,如果不只是使用TextMeshPro的话