Given a JS file JSClass, why this works:
class JSClass extends MonoBehaviour
{
var x: String = '';
function get X() : String { return x; }
function set X(value : String) { x = value; }
}
And this dont work:
var x: String = '';
function get X() : String { return x; }
function set X(value : String) { x = value; }
tonyd
January 5, 2012, 7:14pm
2
Because UnityScript is not true javascript.
You can implement similar behavior though, see this link:
http://www.unifycommunity.com/wiki/index.php?title=ExpandoObject
I think you missed the point; the first code example works fine. The question is why you have to explicitly declare the class in order for the getter/setter functionality to work. The answer is: because. I have no idea.
–Eric
lol eric , usually yer comments are quite tech oriented m i enjoyed that.
Yeah, this looks weird to me too. Thanks Eric.
I think it just works declaring the class because for getters and setters to work you need a class instance.
Eg.
var myClass:MyClass = new MyClass();
myClass.value = v;
And you can’t have an instance wihtout creating the class and it’s constructor function, I guess.