【纯代码】unity计时器,包括触发式
class timer00{ /* 将Timeing()//用FixedUpdate() 计时 当一次计时完成后 调用initialization()进行初始化 */ public bool over; //判断这个来得出计时器是否执行完毕 public bool lastTimeOver ; int endingTime; int newTime = 0; public void initialization(int endingTime0) { over = false; lastTimeOver = false; endingTime = endingTime0; newTime = 0; } public void Timeing() //用FixedUpdate() 计时{必备} { if( !over && newTime < endingTime) { newTime = newTime + 1; Debug.Log(newTime); } else { over = true; } } /* 触发式的timer,也放入fixedupdate void timerTrigger(timer00 shock007) { if(shock007.lastTimeOver != shock007.over) { shock007.lastTimeOver = shock007.over; if(shock007.lastTimeOver == true) { //开始写入触发时执行的代码 } } } */}
页:
[1]