- Home /
Is this C# correct in Unityscript?
Hi all,
is this C# code.
public bool isValid
{
get
{
return _isValid;
}
}
This in Unityscript.
function isValid() : boolean
{
return _isValid;
}
And would all Public bool, int, and float statements that are set the same as the above C# code be the same as what i have done in the unityscript?
Thanks.
Answer by Bunny83 · Aug 06, 2011 at 09:45 AM
That's a C# property. You created a normal function to read it. Properties can also be declared in UnityScript but you will need to explicitly declare the containing class.
See this question.
edit
The difference is in your case you have to call the isValid function manually:
if (myScriptInstance.isValid())
Properties looks like normal variables and can be used like variables but behind the scenes it calls the get / set function
if (myScriptInstance.isValid)
The big advantage is that you can do some extra stuff when someone, somewhere assigns a value to this "variable". In your case the property is read-only since it doesn't have a set function
Ok, looking at the link you gave and what you have typed here, i have come too:
class Valid extends $$anonymous$$onoBehaviour { function get IsValid() : boolean { if (Jigsaw$$anonymous$$ain._isValid) {
}
} }
Now i am getting an error in the line if (Jigsaw$$anonymous$$ain._isValid) which is.
An instance of type 'Jigsaw$$anonymous$$ain' is required to access non static member '_isValid'.
Not sure how to solve it.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Moving from JS to C#, what should I know? 1 Answer
Master Server example in c#! 1 Answer