2017-10-09 3 views
1

のためにだから私はこれを持っていた:Unityは、すべての25個の数字

if (bought.count == bought.needForUpgrade) 
     { 
      bought.timeToComplete /= 2; 
      bought.needForUpgrade += 25; 
     } 

それは良かったが、あなたは1,10,25でアイテムを購入することができますので、私が購入機能を作ったと私はすべてのためのbought.timeToComeplete by 2を減らしたいです25個の数字が通過するので、例えばそのアイテムから1がある場合は25を購入し、次に26を使用します。if statementsをたくさん使っても構いませんが、それは一日中書きたくありませんif(bought.count >= 25 && bought.count <= 50) ..など

+0

あなたが質問を明確にすることはできますか? 25個購入した回数を判断する方法について質問していますか? –

答えて

1

アップグレードした頻度を保存し、次のレベルがあるかどうかを確認する追加の値を単に追加します。 この解決のために、私はbought.countbought.needForUpgradeを前提とは、整数型である:

int boughtLevel = 0; 

if (bought.count/bought.needForUpgrade > boughtLevel) 
{ 
    // Do your stuff here 
    boughtLevel = bought.count/bought.needForUpgrade; 
} 
エルス

あなたが割る前にそれらをキャストする必要があります:

int boughtLevel = 0; 

if ((int)(bought.count/bought.needForUpgrade) > boughtLevel) 
{ 
    // Do your stuff here 
    boughtLevel = (int)(bought.count/bought.needForUpgrade); // Not necessary because boughtLevel is of type integer 
} 
+0

これは機能しました。ありがとう。 – Kalip

関連する問題