Unity3d 计时器 简单原形
public
class
TimerEntry
{
///
<summary>
///
当前开始的时间
///
</summary>
public
float
curStartTime;
///
<summary>
///
当前运行的时间
///
</summary>
public
float
curRuningTime;
///
<summary>
///
总运行的时间, 要倒计时几秒
///
</summary>
public
float
totalRuningTime;
public
static
List
<
TimerEntry
> list=
new
List
<
TimerEntry
>();
///
<summary>
///
添加一个计时器,初始化
///
</summary>
public
static
void
AddEntry()
{
TimerEntry
newEntry =
new
TimerEntry
();
newEntry.curStartTime =
Time
.time;
newEntry.curRuningTime = 0f;
newEntry.totalRuningTime = 3.0f;
list.Add(newEntry);
}
//更新检测
public
static
void
LateUpdate()
{
TimerCheak();
}
static
void
TimerCheak()
{
for
(
int
i = 0; i < list.Count;)
{
TimerEntry
ent = list[i];
ent.curRuningTime =
Time
.time - ent.curStartTime;
if
(ent.curRuningTime > ent.totalRuningTime)
//时间到了
{
//自己的逻辑
list.RemoveAt(i);
continue
;
}
i++;
}
}
}
|