C# 每25个数字的统一

C# 每25个数字的统一,c#,loops,if-statement,unity3d,C#,Loops,If Statement,Unity3d,所以我有这个: if (bought.count == bought.needForUpgrade) { bought.timeToComplete /= 2; bought.needForUpgrade += 25; } 这很好,但是我做了一个buy函数,这样你就可以购买1,10,25个项目,我想减少bunded.timetocomplete,每25个数字的计数通过2个,例如,我从该项目中得到1个,然后我决定购买

所以我有这个:

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

这很好,但是我做了一个buy函数,这样你就可以购买1,10,25个项目,我想减少
bunded.timetocomplete,每25个数字的计数通过2个
,例如,我从该项目中得到1个,然后我决定购买25个,然后我得到26个。我可以用大量的
if语句
,但我不想整天写
if(bunded.count>=25&&bunded.count只需添加一个附加值,以节省升级频率并检查是否达到下一个“级别”。
对于此解决方案,我假设
bunded.count
bunded.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
}

你能澄清一下这个问题吗?你是在问如何确定25次升级的次数吗?