- Home /
call a javascript function from c-sharp
hi , I need to call a javascipt function from a c-sharp file , is there any way to do this ?
thanks
OLD PAGE IS 404 ERROR, THIS IS NEW PAGE:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
heres other code:
http://www.41post.com/1935/program$$anonymous$$g/unity3d-js-cs-or-cs-js-access
Answer by Graham-Dunnett · Oct 17, 2011 at 10:23 AM
Yes. http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html. Also, on this website there is handy white box top right called Search. If you enter "call javascript from c#" in that box and press enter, you'll get lots of help.
thanks for the answer , I know what Search is and you can be sure I've searched a lot before I post my question , all of the results I got was calling a C# function or variable from javascript and there were no results on how to call a javascript function or variable from c# . and your link is like those answers , it answers on how to call a c# variable from javascript
Hmm?! That's not how to do it at all! This is: http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html - like spinner said in the other answer
When ever I try to load the page it say's Page Not Found. Please just tell us what is on the page.
Answer by zpinner · Feb 28, 2012 at 10:35 PM
You'll probably have to add this Javascript into Standard Asset's Folder because of the script compiling order. That will prevent you from sending messages on a two side bridge. You'll be able to call methods from one side only. I had this problem myself and decided to move all my codebase to csharp, to avoid this problem.
This is correct.. in order to access a function in a different language, it needs to be compiled beforehand. Here's a link to a page discussing Unity compile order.
It's one way only, so you'll quickly run into problems with dependencies. (Especially if the script you move to compile earlier itself tries to access other scripts.)
The alternative is to use Send$$anonymous$$essage and Broadcast$$anonymous$$essage but these are quite slow compared to direct access. (nor can you return a variable)
When I researched this issue myself, the general consensus was to stick to one language. (often converting everything to c#)
Oh, true — I hadn’t thought of that. It would really improve the user experience for mixed-language projects if Unity would come up with a way to support compiling scripts written in different languages into the same assembly. The only existing way I know of to do this is to compile the scripts into separate assemblies first, and then merge the assemblies, using either IL$$anonymous$$erge or ILAsm/ILDasm. (See also: $$anonymous$$ixing Languages in a Single Assembly in Visual Studio seamlessly with IL$$anonymous$$erge and $$anonymous$$SBuild).
Your answer
Follow this Question
Related Questions
javascript equivalent of Action? 0 Answers
Multiple Cars not working 1 Answer
Lower player's health from separate script. 2 Answers
Translate this statement from .js to C# 2 Answers
Distribute terrain in zones 3 Answers