- Home /
How to create in array variable in JS/unityscript?
I'm getting an error and I don't know how to get rid of it. I think I can set the values in Start() but I want t learn how to do it this way just for my knowledge.
var input : Array = {u,ur,r,dr,d,dl,l,ul};
function Start()
{
}
I think what I'm doing wrong is that I'm not specifying which type of value is inside of the array(string, float, int, etc). but I don't know how to do this.
I also tried this with no luck
var input : String[] = {u,ur,r,dr,d,dl,l,ul};
I feel you will benefit tremendously from these tutorials: Unity Beginner Scripting
Answer by whydoidoit · Feb 22, 2014 at 04:20 AM
The second format is correct - but I'm assuming u, ur etc aren't variables but the string you want:
var input : String[] = ["u","ur","r","dr" ];
Use [ and ] not { and }
Actually I still have the same error. Do I have to create each of those string variables separately?
Yep that's the csharp syntax (which got us both confused :)