|
I got my score counter to show up on my GUI Text, yet when I switch to another object with the same script its resets the score to zero. What can i change or add to stop it from resetting?
(comments are locked)
|
|
You can declare score as a static variable: A static variable is created once at the program beginning, lives while the program is running and is unique: all script instances use the same variable. Non-static variables exist in each script instance and are independent of each other.
(comments are locked)
|
|
Wait. Are you attaching the same script to multiple objects? Because if you're doing that, this will treat each 'val deer' as different ones. You'd need to setup a control script that acts as a global counter. This controller script can handle things like score keeping.
(comments are locked)
|

What do you mean, 'switch to another object'? I wasn't aware that moving components around was exactly straightforward. If you mean putting another instance of the script on a different object, then of course the score will reset to zero- it's a private member of a different object!