60 lines
1.2 KiB
C#
60 lines
1.2 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class add1 : Label3D
|
|
{
|
|
private int _counter = 0;
|
|
private double _timer = 0.0;
|
|
|
|
// 每秒增加的数值,可以在编辑器中调整
|
|
[Export]
|
|
public int IncrementPerSecond = 1;
|
|
|
|
public override void _Ready()
|
|
{
|
|
// 初始化显示
|
|
UpdateDisplay();
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
_timer += delta;
|
|
|
|
// 每经过1秒,计数器增加
|
|
if (_timer >= 1.0)
|
|
{
|
|
_counter += IncrementPerSecond;
|
|
_timer -= 1.0; // 减去1秒,保留剩余时间
|
|
|
|
// 更新显示
|
|
UpdateDisplay();
|
|
}
|
|
}
|
|
|
|
private void UpdateDisplay()
|
|
{
|
|
Text = _counter.ToString();
|
|
}
|
|
|
|
// 可选:提供方法来手动重置计数器
|
|
public void ResetCounter()
|
|
{
|
|
_counter = 0;
|
|
_timer = 0.0;
|
|
UpdateDisplay();
|
|
}
|
|
|
|
// 可选:提供方法来设置计数器的值
|
|
public void SetCounter(int value)
|
|
{
|
|
_counter = value;
|
|
UpdateDisplay();
|
|
}
|
|
|
|
// 可选:获取当前计数器的值
|
|
public int GetCounter()
|
|
{
|
|
return _counter;
|
|
}
|
|
}
|