- static var RESET_TIME = 2.0;
I am presently defining constants like this. They are in a script named Constant.js, and I call them from other scripts like this:
- if (timer >= Constant.RESET_TIME)
There's nothing wrong with what you're doing. In fact that's a proper and functional use of the static keyword.
Like Quietus said, computational wise there's nothing inefficient about what you're doing there. Though I would make the Constants class a singleton and make all of the "constant" variables into members of that singleton so that you can edit the values of them in the inspector. (Wish static variables were exposed in the inspector :( )
Then you can access the constants by with Constants.instance.RESET_TIME
I am used to ActionScript, so maybe this doesn't apply to UnityScript, but is there a "const" keyword? In ActionScript, I would do it this way:
- static const RESET_TIME:Number = 2.0
(Sorry if I've been useless or confusing in this discussion!)
Other than inspector exposure, is there an obvious reason to prefer singletons over static vars?