I am labouring under the impression that I can call a function in a c# script from a javascript, and vicecersus, by using the normal getcomponent method?
Apologies for the nubish.
I am labouring under the impression that I can call a function in a c# script from a javascript, and vicecersus, by using the normal getcomponent method?
Apologies for the nubish.
When calling between two scripts of different languages, you need to make sure that the code you’re calling is compiled before the code that is doing the calling. To learn when what is compiled, read through this:
While all Unity languages are theoretically compatible, if you have a lot of scripts referencing each other (and for any decently involved project, you will) it can get pretty annoying to have to sort out compile order in very specific detail to avoid errors. Far easier to pick one language and stick with it for any given project.
I can see how it might happen that you have a fairly complex pre-made script to incorporate, and it’s in a different language than what you’re using. In that case though, it probably won’t be referencing your other scripts directly, so it would be safe to throw it in Standard Assets and let it compile first.
So, if its something that I am sure I will be calling in a very known and controlled set of scenarios, I should be able to get away with it.
Thanks for the links and the help!
is this working for iPhone too? Lets say a make a folder which is called “Plugins” and make a C# script in there, it will be compiled first? And when i call the method from a javascript file it will work?
Hey Smallcode,
I agree with Dawvee, best to pick a language and stick with it. I would suggest picking C# since if you add any plugins down the road, to the best of my knowledge, they require C#. Trying to communicate between C# and JS was getting so annoying that I converted all of our project’s JS scripts to C# (probably about 100 scripts total). It’s saved so much headache in the long run
The documentation page I linked should be applicable for Unity iPhone as well, yes.
Hi folks…
Along these lines, we are playing around with Path (thanks AngryAnt!) but are beating our heads against the wall trying to implement the player movement (i.e. DemoSeeker) in javascript when the Path library is implemented in C#. Specifically we are having trouble with the C# interfaces in the library. At one time there was talk about a Javascript demo for Path…
Any suggestions other than converting to C#? I’d really rather not have to go through another learning curve but if we’re going to have to do this, now is probably the time…
Thanks for any input!