_xiaofang/xiaofang/Assets/Script/hylScripts/Free01/FreePanel01.cs
2024-12-12 11:04:48 +08:00

98 lines
1.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FreePanel01 : MonoBehaviour
{
//连接语言的按钮
public Button connectBtn;
//public GameObject FreePanel02;
//这里是计时器相关变量
public Text timerText;
private float timeElapsed; // 游戏运行时间
private bool isRunning = true; //是否在计时
// Start is called before the first frame update
void Start()
{
timeElapsed = 0f;
//connectBtn.onClick.AddListener(OnClickConnectBtn);//监听点击打电话的按钮
}
//当点击连接通话按钮
public void OnClickConnectBtn()
{
return;
}
// Update is called once per frame
void Update()
{
if (isRunning)
{
// 累计游戏运行时间
timeElapsed += Time.deltaTime;
// 更新时间显示
UpdateTimerDisplay();
}
}
// 更新计时器UI显示
private void UpdateTimerDisplay()
{
int minutes = Mathf.FloorToInt(timeElapsed / 60);
int seconds = Mathf.FloorToInt(timeElapsed % 60);
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
// 获取当前的游戏运行时间(秒)
public float GetTimeElapsed()
{
return timeElapsed;
}
// 停止计时器
public void StopTimer()
{
isRunning = false;
}
// 恢复计时器
public void StartTimer()
{
isRunning = true;
}
// 重置计时器
public void ResetTimer()
{
timeElapsed = 0f;
}
}