MyTool小方法 u3d學習總結筆記本
阿新 • • 發佈:2018-11-17
目錄
1.邊緣檢測
2.T觸發
3.計時/計數
1.邊緣檢測
private bool Edge(bool a,ref bool bit){//a 為主判斷,bit為標記位
bool T = a&&!bit;
bit = a;
return T;
}
事件模式
private bool Edge(bool a,ref bool bit, Action event){//a 為主判斷,bit為標記位 bool T = a&&!bit; if(T)event(); bit = a; return T; }
返回目錄
2.T觸發
private bool Trigger(bool a,ref bool bit,ref bool trigger){
if(a&&!bit)trigger = !trigger;
bit = a;
return trigger;
}
事件模式
private bool Trigger(bool a,ref bool bit,ref bool trigger, Action event){ if(a&&!bit)trigger = !trigger; if(trigger)event(); bit = a; return trigger; }
返回目錄
3.計時/計數
private bool Count(ref float seconds,float Tarseconds){//手動清零,重新計時
if(seconds<Tarseconds){
seconds+=Time.deltaTime;//計時/計數
return false;
}else{
return true;
}
}