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 initialization
    void Start () {
        textTest = GetComponent <Text> ();
    }

        // 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<Text>();
        if (i == 0)
        {
            content = textTest.text;
            i++;
        }
        textTest.text = "";
        timer = charsPerSeconds;
        isActive = true;
        currentPos = 0;
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值