unity四种Text总结

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UI_text : MonoBehaviour {
    //画布下的 Text 可添加 Shadow与OutLine组件进行装饰
    public Text Text_canvas; 
    //世界object 3D Text 可根据Fontsize 进行缩放 
    public TextMesh Text_3d;
    //空物体添加 Gui Text组件 将transform组件的位置改为vector3((0-1),(0-1),x)否则将不显
    public GUIText Gui_Text;

    //计时操作
    float number;
    float second;
    float minute;
    float hour;
    string timedemo;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        number += Time.deltaTime;
        if (number > 1)
        {
            second ++;
            number -= 1;
        }
        if (second > 60)
        {
            second -= 60;
            minute++;
        }
        if (minute > 60)
        {
            minute -= 60;
            hour++;
        }
        if (hour > 24)
        {
            hour -= 24;
        }
        timedemo = string.Format("{0}时:{1}分:{2}秒", hour, minute, second);
    }
    //Ogui 代码控制一般做计时器
    private void OnGUI()
    {
        GUI.Label(new Rect(Screen.width-550, Screen.height-100, 500, 100), "OGUI_text:  "+ timedemo);
    }
}

猜你喜欢

转载自blog.csdn.net/fanfan_hongyun/article/details/81484494
今日推荐