_xiaofang/xiaofang/Assets/Script/hylScripts/Free01/FreePanel01.cs

98 lines
1.5 KiB
C#
Raw Normal View History

2024-12-11 15:53:49 +08:00
using System;
2024-12-11 11:10:48 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FreePanel01 : MonoBehaviour
{
2024-12-11 17:00:42 +08:00
2024-12-11 16:51:06 +08:00
public Button connectBtn;
2024-12-11 17:00:42 +08:00
2024-12-11 17:07:18 +08:00
//public GameObject FreePanel02;
2024-12-11 11:10:48 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ǽ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>
public Text timerText;
private float timeElapsed; // <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
private bool isRunning = true; //<2F>Ƿ<EFBFBD><C7B7>ڼ<EFBFBD>ʱ
2024-12-11 15:53:49 +08:00
2024-12-11 11:10:48 +08:00
// Start is called before the first frame update
void Start()
{
timeElapsed = 0f;
2024-12-11 17:00:42 +08:00
2024-12-11 16:51:06 +08:00
connectBtn.onClick.AddListener(OnClickConnectBtn);
2024-12-11 11:10:48 +08:00
}
2024-12-11 16:51:06 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>ť
public void OnClickConnectBtn()
{
return;
}
2024-12-11 11:10:48 +08:00
// Update is called once per frame
void Update()
{
if (isRunning)
{
// <20>ۼ<EFBFBD><DBBC><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
timeElapsed += Time.deltaTime;
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʾ
UpdateTimerDisplay();
}
}
// <20><><EFBFBD>¼<EFBFBD>ʱ<EFBFBD><CAB1>UI<55><49>ʾ
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);
}
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
public float GetTimeElapsed()
{
return timeElapsed;
}
// ֹͣ<CDA3><D6B9>ʱ<EFBFBD><CAB1>
public void StopTimer()
{
isRunning = false;
}
// <20>ָ<EFBFBD><D6B8><EFBFBD>ʱ<EFBFBD><CAB1>
public void StartTimer()
{
isRunning = true;
}
// <20><><EFBFBD>ü<EFBFBD>ʱ<EFBFBD><CAB1>
public void ResetTimer()
{
timeElapsed = 0f;
}
2024-12-11 17:00:42 +08:00
2024-12-11 11:10:48 +08:00
}
2024-12-11 17:00:42 +08:00