- Home /
How can I overload operators in Unity Javascript
I tried using this code to modify the [] operator:
static operator [] ( iRow:int ):float { return parseFloat(m[iRow]); }
it did not work but in the unity reference, there were some operator overloads defined in the same way.
Answer by Mike 3 · May 31, 2010 at 06:29 PM
There isn't a [] operator.
In c# you can created indexers (the things arrays and hashtables use) like this:
public string this[string key]
{
return internalStringDictionary[key];
}
but i don't think js has the relevant syntax to express it
I don't know whether your answer was true at the time, but UnityScript definitely has a [] operator now. I'm using it to access my many arrays right now.
Your answer
Follow this Question
Related Questions
Can't assign a component? 2 Answers
Overload Operator in UnityScript? 0 Answers
Whats the result of comparing two objects of a user defined type using the equals operator? 1 Answer
Operator + cannot be used to combine Object and Int 1 Answer
error CS0019: Operator `>' cannot be applied to operands of type `UnityEngine.Vector3' and `int' 0 Answers