值不会因方法而改变,它们保持不变

Value not change by method they remain same

我想使用一种方法更改我的值。值在方法中发生变化,但在方法之外没有变化,它们保持不变。我第一次尝试通过方法更改这些值,所以我不知道它们是否可以更改。任何参考或帮助:) 代码:

方法:-

void WeaponUpdateMethod (int objUpdateValue, float  time, string updateMoney, string saveData, float sliderValue)
{
    buttonClick.Play ();
    int t = objUpdateValue;
    if (t < 1 && totalMoney > 5000) { 
        t = 1;
        totalMoney -= 5000;
        time = 12f;
    } else if (t != 2 && t < 2 && totalMoney > 10000) { 
        t = 2;
        totalMoney -= 10000; 
        time = 15f;
    } else if (t != 3 && t < 3 && totalMoney > 14000) { 
        t = 3;
        totalMoney -= 14000; 
        time = 17f;
    } else if (t != 4 && t < 4 && totalMoney > 25000) { 
        t = 4;
        totalMoney -= 25000; 
        time = 20f;
    } 
    if (t == 0) {
        updateMoney = "" + 5000;
    } else if (t == 1) {
        updateMoney = "" + 10000;
    } else if (t == 2) {
        updateMoney = "" + 14000;
    } else if (t == 3) {
        updateMoney = "" + 25000;
    } else if (t == 4) {
        updateMoney = "full";
    }
    PlayerPrefs.SetInt (saveData, t);
    PlayerPrefs.SetInt ("totalMoney", totalMoney);
    PlayerPrefs.Save ();
    sliderValue = t;
    objUpdateValue = t;
    print (objUpdateValue);     
    print(objUpdateValue+" from method");
} 

在这里使用:-

public void UpgradeSpeedUp ()
{
    // to upgrade speedUp  
    WeaponUpdateMethod (speedUpUpdateValue, ManageSingleShotPowers.speedUpTime, speedUpUpdateMoney.text, "spedUpUpdate", speedUpSlider.value);

    print(speedUpUpdateValue +" from calling");
}

在C#中,参数默认按值传入。您必须指定要通过引用传入的参数。您可以通过在参数前面使用关键字 ref 来实现,例如 ref int objUpdateValue.