有人说UGUI的Text不能换行,有人说可以通过\n换行,并附上了整条字符串。 
其实他们根本就不在一个频道!! 
这么说吧,通过代码直接给Text组件的text赋值"<color=red>XXXX</color>\nXXXX"绝对是可以换行效果的;然而,在Inspector面板的Text组件里输入同样的内容就不行,哪怕手拙复制进去都不对,这尼玛什么鬼!? 
后来发现,原来它把\n偷偷变成了\\n了,所以我们只要把它变回来就行啦! 
[csharp] view plain copy
  1. using UnityEngine;  
  2. using UnityEngine.UI;  
  3.      
  4. public class RyanTextLineFeed : MonoBehaviour  
  5. {  
  6.     Text myText;  
  7.      
  8.     void Start ()  
  9.     {  
  10.         myText = GetComponent<Text> ();  
  11.         myText.text = myText.text.Replace ("\\n""\n");  
  12.     }  
  13. }  

unity UGUI Text换行问题unity UGUI Text换行问题

http://blog.csdn.net/zjw1349547081/article/details/53390609

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
相关资源
相似解决方案