- Home /
Question by
pdh1kid · Dec 04, 2010 at 04:24 PM ·
javascriptvariablescene-loadingloadlevel
Maintaining var when another scene is loaded(JS)
Ok so I have a character that has a money and score variable that I would like to keep the same value when I load another level/scene. Whenever I load the character the values revert back to their origonal defaut settings of zero. Is there any way to maintain the score/money variable when I change levels? If whoever answers this could use JS that would be really helpful.
Comment
Answer by Mike 3 · Dec 04, 2010 at 04:34 PM
Static variables will persist through scenes:
static var test : int = 0;
Just remember that the variable will be shared between all instances of the script
Answer by ahmetDP · Dec 04, 2010 at 04:47 PM
You can also look into PlayerPrefs for keeping such info of your player.
Your answer