- Home /
Array in JS NOT Working with Components?!
I have a Javascript, which is very simple. I get ONE Error that i normally shouldn't get, because i did it like everyone else.
var = Component[];
(This is not working, I'll get an error. But if i use
var = Component;
Then it works?!
I really need help, thanks
Answer by Bunny83 · Apr 08, 2016 at 02:18 AM
You really should post your actual code and your actual error you get. Your both lines don't make any sense and won't compile. "var" is a keyword to declare a variable in UnityScript. It must be followed by a variable name. Next thing is you use the "equals" (=) operator which is used for assignments. However Component[]
and Component
are Types and not values which could be assigned to a variable.
You might wanted to specify the variable type, but that's done with a colon (:)
var myVariableName : Component[];
Answer by SandipVala · Apr 08, 2016 at 07:03 AM
See reference for how to declare array Array Declaration in Javascript
That's irrelevant for Unity as your link is about (web-) Javascript and not about UnityScript. UnityScript just has a syntax similar to Javascript but is a totally different language. UnityScript is actually a compiled .NET / $$anonymous$$ono language.
See UnityScript versus JavaScript and Head First into Unity with UnityScript