Unity中UGUI首行缩进两个空白字符解决方案 您所在的位置:网站首页 unity中textTMP中文方块 Unity中UGUI首行缩进两个空白字符解决方案

Unity中UGUI首行缩进两个空白字符解决方案

2024-07-12 05:34| 来源: 网络整理| 查看: 265

本想要在UGUI text中首行缩进,结果发现空格不好用,找了三种解决方案

1.在脚本中直接赋值text是最简单的 

 TextTest.text =“\u3000\u3000”+"字符串";

2.UGUI的Text如果在编辑器直接输入显示我们可以自定义某几个字符串的alpha值

 -----

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 initialization void Start () { textTest = GetComponent (); } // Update is called once per frame void 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(); if (i == 0) { content = textTest.text; i++; } textTest.text = ""; timer = charsPerSeconds; isActive = true; currentPos = 0; } }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有