x


Public variables not updating?

I'm trying to show the player's total score at the end of the game, but it seems that it's only displaying the value that I originally declared it as.

For example, here's some psuedo code:

public int score = 1;
score = kills * 50;

No matter how many kills I get, my score is always displayed as 1. How do I fix this?

Edit: I guess it has something to do with the order of my code. I'm accessing the score variable from a separate scene and separate script. How do I make sure everything goes in the right order?

more ▼

asked Oct 17 '10 at 07:03 AM

Lanipoop gravatar image

Lanipoop
62 6 8 15

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

1 answer: sort voted first

Hey,

I think you have to use static vars for what you're trying to do.

static var score : int = 1;

you'd access the variable with:

myScriptName.score = 

I'm probably not 100% correct here but I think normal vars (var score : int) are already public, meaning that you can see them in the inspector and access the throughout that script and have them accessible through GetComponent.

As opposed to a private var (private var score : int) that is not visible in the inspector and is only accessible from that script.

Hope it helps!

Cheers!

more ▼

answered Oct 17 '10 at 11:21 AM

Jaywalker gravatar image

Jaywalker
529 15 21 30

Wow that worked, thank you so much!!!

Oct 17 '10 at 10:14 PM Lanipoop
(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:

x355
x16

asked: Oct 17 '10 at 07:03 AM

Seen: 1099 times

Last Updated: Oct 17 '10 at 07:40 AM