In C#, I can declare properties like so:
public int Health
{
get { return _health; }
protected set { _health = value; }
}
- Does JS also support properties?
- If so, how can I declare them?
I already know I can just have Get/Set functions but that is not what I am after.
Yes, but you have to do it in explicitly declared classes
class Test extends MonoBehaviour
{
var moo = 1;
function get Moo() : int { return moo; }
function set Moo(value : int) { moo = value; }
}
That is then accessible the same way as c# properties ( blah.Moo )
If you try it with implicit classes you'll get some fantastically odd errors
Another caveat - you can't do static properties