Accessing C# variable from Javascript via GetComponent

I moved my C# file in the standard assets folder and I am able to do a GetComponent(“csharpfilename”) but when i try to access an int in the csharp class i get an error saying the variable is not a member of the component

GetComponent(“componentName”) returns a Component, not your script type - that’s why Unity doesn’t know how to access the script variables. You could use the typed GetComponent version instead:

  var csScript: YourCsScript = GetComponent(YourCsScript);

But JS won’t recognize the type YourCsScript unless the file YourCsScript.cs has already been compiled. If the C# file is in Standard Assets, you can move the JS scripts to some custom Assets subfolder, like Assets/JScripts, for instance - scripts in such folder will be compiled after the ones in Standard Assets. But be aware that the opposite isn’t true: scripts in JScripts can’t be seen by the ones previously compiled.

Don’t use the string version of Getcomponent since it just returns a Component reference. In UnityScript use either GetComponent(CSharpClassName) or GetComponent.()