- Home /
Reference JS string to C#
I'm trying to reference a string from a JS script and reference the value in a C# script. I know that I have to place the JS script in a special folder, but I don't know the line of code to reference a JS script, I know to reference a C# is : string myusername = ScriptName.myusername . However I can't seem to do the same for JS. Does it have to do with something I have to adjust in Mono Develop? Please help.
Answer by fafase · Jun 11, 2013 at 06:25 AM
Nope, as long as your Js script is in Standard Asset folder, you reach it the same way:
JSScriptName script = GetComponent<JSScriptName>();
string str = script.member;
Doesn't work, it needs an object reference (Which I don't know how to do).
$$anonymous$$ongAPI script = GetComponent(); string myusername = $$anonymous$$ongAPI.myusername;
That's what I typed.
$$anonymous$$yUnityObject = The Object my scriptis on; $$anonymous$$ongAPI = script; myusername = string;
It does not work because you are doing wrong. http://unitygems.com/script-interaction1/
Well,....all of them...GetComponent() should take a parameter, if you use C# you may use the generic version, then the way you access it $$anonymous$$ongAPI.myusername is also wrong since you access a non-static variable you need to use script.myusername.