- Home /
Variable value not changhing
The variable value is not changhing and it is really weird i need help.
So...
TotalBullets = TotalBullets + AmmoFromBoxes;
and
TotalBulletsText.text =""; TotalBulletsText.text += TotalBullets; // kinda weird but thats how i do it
well the variable value does not change. the text remains the same. if i do
Debug.Log(TotalBullets);
in
void Update()
then the value goes one frame the previous amount and the other frame the amount that it should be.
150 120 150 120 150 120 ...you get it
if i do it again
180 120 180 120 ...
And if i just
Debug.Log(TotalBullets);
after the variable increase it gives me the right value everytime...
TotalBullets is private
I tried many things but it seems like this is a bug. I am using unity version 5.3.5f1.
Pls help
Answer by SohailBukhari · Sep 23, 2016 at 06:03 PM
@username use TotalBulletsText.text = TotalBullets.tostring(); it will helps
Check the code it may be possible that you are using values somewhere else in the code and your values replace
Answer by terminator2016 · Sep 23, 2016 at 07:09 PM
you have to configure the base of the starter i think.
Answer by RazvanUzum · Sep 23, 2016 at 07:08 PM
So...i replaced the variable TotalBullets with PlayerPrefs.GetInt("TotalBullets") so now it works but i still want to know why it did not work with the variable ... its very weird i checked it multiple times and i think its a bug ... But yea thx
I think you'd need to show us more code (the actual code) and explain things more fully (for example, you cannot have simply replaced that variable with a call to PlayerPrefs.GetInt(), since you cannot assign to the latter, plus you are not using PlayerPrefs.SetInt() anywhere).
But one possibility is that you've got multiple instances of the script, and the variable is only being changed in one of them. If you've moved to system where those different instances are both getting a value from a common place, then one would expect the symptoms to go away.