x


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.

more ▼

asked Dec 04 '10 at 04:24 PM

pdh1kid gravatar image

pdh1kid
54 8 9 13

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Dec 04 '10 at 04:34 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

(comments are locked)
10|3000 characters needed characters left

You can also look into PlayerPrefs for keeping such info of your player.

more ▼

answered Dec 04 '10 at 04:47 PM

ahmetDP gravatar image

ahmetDP
1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x823
x263
x106

asked: Dec 04 '10 at 04:24 PM

Seen: 983 times

Last Updated: Dec 04 '10 at 04:24 PM