#accessing static variable in another script
1 messages · Page 1 of 1 (latest)
Why are you accessing it through script
When you've made it static...
I don't think you understand what static means
you dont need to pass it to another script becouse the other script can access the static score.
The way I explain static is Imagine you have 1 script called Cars and you put that Cars script into 3 objects. Each one of them has a seperate Variable called GassPrice. Then you can put a gass price into each object (example: 3, 2, 15). But if you want them to always have the same gass price no matter what and you want to be able to change it so every single one of them has it. You can set the GassPrice static and as soon as you change it every single one of objects will have the same variable.
So basicaly static makes a variable or function the same in each instant.
Furthermore why is static being used here anyway? I think your code design is flawed
You can access the score like this
int score;
Void Awake()
{
score = CrystalScore.score;
}
tysm bro i thought static means it will remain the same in all scenes, but not scripts. Now u understand
tysm it works