- Home /
+= sign not working properly unity
{
if (Calendar_script.year==2016)
if (Calendar_script.months==1)
if (detailsRegenyear1.cash1<10)
detailsRegenyear1.RegenPrice1 += 2;
}
That works fine but when I change scenes and go back into that scene with that script in in it doubles the amount.
sounds more like you've some sort of static variable mixed with a don't destroy on load crazyness going on (see robertbu's comment about guessing).
$$anonymous$$ake sure you didn't set whatever gameobject that script is attached to do "DontDestroyOnLoad".
DontDestroyOnLoad (Object object);
If you did that, then your object will stay alive in-between scenes, and so will all the values on the script.
Please post more code though, so we can have an easier time helping you.
Answer by robertbu · Nov 04, 2014 at 11:14 PM
I doubt there is a problem with +=. Without seeing more code, we can only guess as the issue. Maybe you have more than one game object with the above script. Is 'detailsRegenyear1' static?