1. 程式人生 > >MyTool小方法 u3d學習總結筆記本

MyTool小方法 u3d學習總結筆記本

目錄

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;
	}
}

返回目錄