using UnityEngine; using UnityEngine.UI; /// /// 修复InputField输入时因空格引起的换行显示错误问题 /// public class TextFixSpace : MonoBehaviour { //代替空格的空格符 private static readonly string no_breaking_space = "\u00A0"; private Text m_Text; void Start() { m_Text = GetComponent(); // 修复空格符 m_Text.text = m_Text.text.Replace(" ", no_breaking_space); } }