x


Saving And Loading A Float

Hello

Im trying to save and load my exp heres my script

var exp : float;

function Update () {
    AddjustExp(0);
}

function AddjustExp(adj) {
    exp += adj;
}

how can i make it so if i press a gui button in the top middle of the screen it will save my exp and when i load another level it loads my exp.

Thanks

more ▼

asked Apr 19 '11 at 12:22 PM

Aydan gravatar image

Aydan
180 28 37 47

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

2 answers: sort voted first

If you want to save the value even across multiple game sessions use PlayerPrefs.
To save your "exp":

PlayerPrefs.SetFloat("currentXP",exp);

To load it:

exp = PlayerPrefs.GetFloat("currentXP",0);

The "0" at the end is the default value that is returned if it hasn't been saved yet. You can use any name you like to save values but it should be something you can remember ;)

more ▼

answered Apr 19 '11 at 03:11 PM

Bunny83 gravatar image

Bunny83
45.4k 11 49 207

Thanks works great

Apr 19 '11 at 11:01 PM Aydan
(comments are locked)
10|3000 characters needed characters left
// Make this game object and all its transform children
// survive when loading a new scene.
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
more ▼

answered Apr 19 '11 at 12:54 PM

Aldwoni gravatar image

Aldwoni
865 27 30 34

Right, for manager scripts that should survive the whole game that's the right way.

Apr 19 '11 at 03:04 PM Bunny83
(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:

x3695
x438
x437
x322

asked: Apr 19 '11 at 12:22 PM

Seen: 756 times

Last Updated: Apr 19 '11 at 12:22 PM