本文主要是介绍Unity中UGUI首行缩进两个空白字符解决方案,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本想要在UGUI text中首行缩进,结果发现空格不好用,找了三种解决方案
1.在脚本中直接赋值text是最简单的
TextTest.text =“\u3000\u3000”+"字符串";
2.UGUI的Text如果在编辑器直接输入显示我们可以自定义某几个字符串的alpha值
<color=#FFFFFF00>-----</color>
3.如果需要将段落逐字字打印出现,上述两种方法都无法实现首行缩进,做了一个取巧的
方法,找到两个空白字符,没错哈,下面一行开头就是两个空白字符,自行复制粘贴!
附Text逐字打印脚本]
public class TextType : MonoBehaviour {int i = 0;public float charsPerSeconds = 0.2f;private string content;private Text textTest;private float timer;private int currentPos;private bool isActive;// Use this for initializationvoid Start () {textTest = GetComponent <Text> ();}// Update is called once per framevoid Update () {if (isActive == true){StartTyperEffect ();}}public void TyperEffect(){isActive = true;}private void StartTyperEffect() {timer += Time.deltaTime;if (timer > charsPerSeconds) {timer -= charsPerSeconds;currentPos++;textTest.text = content.Substring (0, currentPos);if(currentPos >= content.Length) {FinishTyperEffect ();}}}private void FinishTyperEffect() {isActive = false;timer = charsPerSeconds;currentPos = 0;textTest.text = content;}void OnEnable(){textTest = GetComponent<Text>();if (i == 0){content = textTest.text;i++;}textTest.text = "";timer = charsPerSeconds;isActive = true;currentPos = 0;}
}
这篇关于Unity中UGUI首行缩进两个空白字符解决方案的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!