chenxin
2020-10-22 85f0d13945f3aef5aef1b3c1b47c77cea0514c17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
 
public class BossWarning : MonoBehaviour
{
    /// <summary>
    /// 对应的时间显示
    /// </summary>
    public TextMeshProUGUI timeText;
 
    protected int lastIntSec = 0;
    protected float timeDisSec = 0;
 
    // Start is called before the first frame update
    void Start()
    {
        
    }
 
    /// <summary>
    /// 设置倒计时的时间.
    /// </summary>
    /// <param name="cdtime"></param>
    public void setCountDownTime( float cdtime)
    {
        timeDisSec = cdtime;
        lastIntSec = (int)Math.Ceiling(cdtime);
        timeText.text = lastIntSec.ToString() + "s";
    }
 
    // Update is called once per frame
    void Update()
    {
        timeDisSec -= Time.deltaTime;
        int tint = (int)Math.Ceiling(timeDisSec);
        if (tint < 1)
            tint = 1;
        if( tint != lastIntSec)
        {
            lastIntSec = tint;
            timeText.text = lastIntSec.ToString() + "s";
        }
    }
}