【3Dゲームエンジン】Unity質問スレッド21 [転載禁止]©5ch.net
レス数が900を超えています。1000を超えると表示できなくなるよ。
0901名前は開発中のものです。
2016/01/07(木) 22:50:31.54ID:jc2wiw05もっと効率良くはなると思うがわかりやすく書くとこんなところかね
//ガードしているかどうか
bool isGuarded;
//fireRateのうちどこで撃つか
int fireTiming;
//何フレームに1回撃つか、メソッド内に数値リテラル書きたくないしインスペクタから変更したいが面倒なのでパブリック
public int fireRate=5;
void Update(){
if(Input.GetKeyDown(KeyCode.Z)){
//Zが押されたタイミングをキャッシュしとく
fireTiming=Time.frameCount%fireRate;
}
bool fire=Input.GetKey(KeyCode.Z);
bool guard=Input.GetKey(KeyCode.X)&&!fire;
if(fire&&Time.frameCount%fireRate==fireTiming){
this.Fire();//弾を発射するメソッド
}else if(!isGuarded&&guard){
isGuarded=true;
this.Guard();//ガード開始するメソッド
}else if(isGuarded&&!guard){
isGuarded=false;
this.Unguard();//ガード解除するメソッド
}
}
レス数が900を超えています。1000を超えると表示できなくなるよ。