- Home /
Can I run static var from another script ؟؟؟
Can I run static var from another script ؟؟؟
Thx....
Answer by anszwa · Oct 07, 2011 at 10:43 PM
Hy, yes i think so, I always did it that way (JavaScript):
For expample if I have a script called "PointScript", with the variable
public static var counter : int = 0;
If i want to get this variable in an other script you have to write
private var counter : int;
counter = PointScript.counter;
Dont forget to set it in the update function if the value changes while runtime! Was it that you meant or do I have blamed my selve^^
Answer with examples is very good.. They make 70% of my understanding ....
Thx...
Answer by aldonaletto · Oct 07, 2011 at 10:38 PM
What do you mean with "run static var"? You can access a static var using the script type (which is the script name, without quotes or extension) followed by .variableName: if the variable health is in the script HealthControl.js, you can access it from any other script as HealthControl.health.
You can write and read the static var, but "run"... what does it mean?
Your answer
![](https://koobas.hobune.stream/wayback/20220613001229im_/https://answers.unity.com/themes/thub/images/avi.jpg)