x


calculate playerprefs and display

Ok so i have multiple playerprefs, what i would like to do is add up all the values in my playerprefs and display the final value

i was thinking something like this:

function Update () {

guiText.text = (PlayerPrefs.GetInt("Level81Score"+"Level15Score"+"Level15Score")).ToString ();

}

more ▼

asked Feb 22 '12 at 07:11 AM

sunnykhan4u21 gravatar image

sunnykhan4u21
3 5 5 9

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

1 answer: sort voted first

Just use GetInt for each entry. You can't combine the strings like that.

more ▼

answered Feb 22 '12 at 07:57 AM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

Thanx Eic5h5!

Ok iv worked it out myself, my solution is below, probably not the best since im not a coder, hope this helps someone.

static var Count : int = 0;

function Start(){

Count += PlayerPrefs.GetInt("Level1Score"); Count += PlayerPrefs.GetInt("Level2Score"); Count += PlayerPrefs.GetInt("Level3Score");

//Show Score guiText.text = (Count).ToString ();

}

@script RequireComponent (GUIText)

Feb 23 '12 at 02:15 AM sunnykhan4u21

That's fine.

Feb 23 '12 at 02:30 AM Eric5h5
(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:

x302
x280
x147
x35
x5

asked: Feb 22 '12 at 07:11 AM

Seen: 504 times

Last Updated: Feb 23 '12 at 02:30 AM