当前位置:网站首页>Unity writes timetables (without UI)

Unity writes timetables (without UI)

2022-07-05 04:55:00 yaohuiyaoo

1. Key code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour {
// millisecond
private float ms = 0f;
// Hours
private int h = 0;
// branch
private int m = 0;
// second
private int s = 0;
// character string
private string timeStr = string.Empty;
void Update () {
// Accumulate the running time of the game
timer += Time.deltaTime;
// Millisecond is 0-1 Decimals of , exceed 1, Carry clear , Recalculate
if (timer >= 1f) { s++;timer = 0; }
if (s >= 60) { m++;s = 0; }
if (m >= 60) { h++;m = 0; }
if (h >= 99) { h = 0; }
}
private void OnGUI()
{
// Convert a number to a string
timeStr = string.Format("{0}:{1}:{2}", h, m, s);
//GUI style
GUIStyle style= new GUIStyle();
// Set font size
style.fontSize = 100;
//GUI label
GUI.Label(new Rect(10,10,100,200),timeStr,style);
}
}

原网站

版权声明
本文为[yaohuiyaoo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140626298789.html