Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Other than the obvious language differences, how do JavaScript and C# differ when developing games in Unity3D?

  • Is there a noticable performance difference?
  • Is the JS code packaged as-is? If yes, does this help the game's moddability?
  • Is it possible to use libraries developed for one language while developing in the other one?
  • Can the two languages be mixed in the same Unity project; coding some parts in C# and others in JavaScript?
share|improve this question

closed as off-topic by bummzack, Josh Petrie Jul 7 '14 at 15:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – bummzack, Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

There is non writing component wise. But C# allows for extra stuff like DLL imports. Other than that it's a "choice". And completely subjective. Don't forget, there is also Boo in which you can write your code. – Sidar Mar 1 '14 at 22:07
Helpful question with objective answers - seems unfair that it was closed. – UpTheCreek Nov 11 '14 at 13:16
There are two main reasons this question was closed, and they don't have to do with the utility of the question or the objectivity of the answers. First, the post asks more than one unrelated question. Second, some of the questions asked are too discussion oriented and/or two broad to be appropriate as-written. How "helpful" or popular a question is, or how good the answers are, are both independent from whether or not the question is appropriate for the site. – Josh Petrie Nov 11 '14 at 22:39
up vote 10 down vote accepted

Is there a noticable performance difference?

No. There technically is a very small performance difference, but it is not significant enough to base your choice of language on in most cases.

Is it possible to use libraries developed for one language while developing in the other one?

Yes. As long as you make sure to keep the folder structure recommended by the developer of the library, that library can be accessed from any language. This has to do with the Unity compilation order. Some features in IDEs, like autocomplete, may not work for the chosen library though. (EDIT: this can be fixed by using the free plugin UnityVS for Visual Studio.)

Is it possible to mix the two languages in the same Unity project by coding some parts in C# and others in Javascript?

Again, yes. It gets complicated quickly though, as you have to make sure everything is compiled in the right order. While it is technically possible, I'd recommend you pick one language and stick with it.

Which language has better game dev specific resources available (books, websites, forums)?

Hard to say. From browsing the forums, I'd say Javascript has slightly more tutorials and code examples. Code is generally pretty easy to port to the other language though, and since libraries are usable cross-language, this will most likely not be a major issue.

share|improve this answer

The very first question all beginning Unity developers have is C# or JS. Always go with C#.

Now, right now you may be thinking, "But I don't want to learn C# and I already know a bit of JavaScript."

But the misleading thing you need to consider is that Unity JavaScript is not JavaScript. It is a superficial veneer of ECMA syntax over .NET CLR. It does not do any of the cool things JavaScript does like anonymous enclosures and function references the way you would use them normally. It has it's own arrays that dont match up with normal .net arrays, and you'll encounter many pitfalls and limitations that you could've just avoided by using C#. Unity JavaScript is only a candy-coated layer of syntax designed to make .NET appear less intimidating, nothing more. It will do you more harm than good.

share|improve this answer

First off, I would recommend C# over JavaScript for programming in Unity for two main reasons. The first reason comes down to the strong/weak typing difference that you kind of dismissed. I do think strong typing works better than weak typing on a conceptual level, but frankly that's a whole big argument people have and so I'll focus more on a specific practical issue: Deploying to iOS (and possibly other platforms too, but that's the only one I know for sure) requires static typing. Unity actually even has a directive "#pragma strict" that can force static typing in JavaScript for this reason, but that just brings me to my second reason...

Secondly, the JavaScript in Unity is not entirely the same as JavaScript in a browser. This creates problems when you try to apply knowledge from outside Unity (ie. the majority of resources about JavaScript) to programming in Unity. This is why many Unity developers refer to the language as UnityScript.

Now to address your specific questions:

Is there a noticable performance difference?

Not really, no (some details)

Is the javascript code packaged as-is? And if yes, does this help the game's modability?

Depends on the platform, and no this doesn't really help modability

Is it possible to use libraries developed for one language while developing in the other one?

I think so (although I've never needed to do this, because all the libraries I use were programmed in C#)

Is it possible to mix the two languages in the same Unity project by coding some parts in C# and others in Javascript?

Yes (although I try to avoid it, for consistency reasons)

share|improve this answer… might want to add this to your answer. Upvoted. – Grey Mar 1 '14 at 22:39
interesting linke, added – jhocking Mar 1 '14 at 23:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.