Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by smtabatabaie · Oct 17, 2011 at 10:22 AM · c#javascriptfunction

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ti89TProgrammer · Feb 28, 2012 at 09:41 PM 0
Share

See also how to access javascript method using c sharp.

avatar image frogsbo · Mar 08, 2014 at 12:46 AM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image smtabatabaie · Oct 17, 2011 at 11:20 AM 0
Share

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

avatar image cregox · May 17, 2012 at 04:57 PM 0
Share

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

avatar image Jem_Stone · Oct 27, 2015 at 12:21 AM 0
Share

When ever I try to load the page it say's Page Not Found. Please just tell us what is on the page.

avatar image
4

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JinxM · Feb 28, 2012 at 11:30 PM 1
Share

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#)

avatar image ti89TProgrammer · Feb 29, 2012 at 12:47 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges