JavaScript vs C#

I don’t know if there has been a topic about this but I can’t find one, so here it is…

I’m just starting with Unity having a C++ game dev background, it’s not a matter for me of “which one is easier to use”, but its pros and cons of each language when working with Unity.

Apart from syntax differences, where do they differ?
Can I do with JS absolutely everything (always talking about Unity) that I can with C#, and the opposite?

As far as I can tell, you can access all Unity features with JavaScript and C#, including the unusual ones such as attributes which associate functions with menu items. At one point, there were some features which were only accessible from C#, but I believe these have all been made accessible for JavaScript in recent versions.

At this point, it probably just comes down to a matter of preference and whether or not you want the specific features of a particular language (such as properties and all-encompassing static typing in C#).

Also keep in mind that currently some of the JS syntax or handling is actually leveraging the .Net framework… Such as strings, arrays and I believe some others that I can’t think of off the top of my head.

HTH,

– Clint

And can you not mix and match anyway, guys? Write scripts for X, Y and Z in one language and write scripts for A, B and C in the other (if you’re more comfortable? The scripts simply get pulled into the game (objects) anyways so can you not mix as needed?

Yes, to a point, but crossing language barriers can be a bit tricky. It’s easy enough if your scripts are highly self-contained, though.

I find JS a little less verbose and it is easy to use dynamic typing if you have the need. Coming from a C++ background I do not know if you would be interested in that :stuck_out_tongue:

It does not make a difference whether u use c# or javascript when u write the behaviours that u attach to game objects.

but u will have to use a .net language if u intend to produce .net dlls and access them in unity from ur behaviour scripts.

in this case u may prefer to choose c# and code every thing with it.

I write my core classes in VS.net using c# and access them (compiled dlls) in unity from my scripts which i also code using c#.

supporting .net dlls is a very powerful feature of unity, it lets u access any .net library.

in the future, i intend to try accessing a database mapped using NHibernate from within unity.

You can also produce .net dlls from JavaScript code. The JavaScript compiler is located at /Applications/Unity/Unity.app/Contents/Frameworks/MonoCompiler.framework/us.exe

is there an example freyr i would be most interested in writing .net dll’s with javascript