JavaScript or C#

Hi guys,

I’m relatively new to Unity and the forums, so I hope that I’m asking my question in the right place. I have about 2 - 3 years of experience with C++ and Java. And by experience, I mean I’ve taken some classes, no actual jobs. I’d say that I’m comfortable with both languages, but not an expert in either by any means.

Anywho, as I understand it, scripts in Unity may be programmed with C#, JavaScript, UnityScript, and Boo. I have little to no experience with C#, but have taken a look at some scripts and the syntax doesn’t seem to far off from the likes of C++ and Java. However, I have also looked at some JavaScript scripts and found that it is way different from C++, Java, C# or anything else I have experience with. I would prefer to just try and adapt to C# since it won’t be such a steep learning curve, however it seems that a lot of the educational material out there is taught with JavaScript.

Here’s my question: Should I just push ahead and continue with C#? Or would you guys recommend that I pick up a book with JavaScript examples, such as Sue Blackman’s Beginning 3D Game Development with Unity 4, and learn the JavaScript syntax. I’m also open to any other suggestions!

Thanks for your time and input!

Both are equally capable.

Choose the one you like better.

It is actually pretty easy to learn both - so just start with the one that you feel comfortable with.

C# is the most similar of Unity’s languages to C++ and Java, so you’ll probably get your fastest start by going with that. As for your later question, most of the difference between JavaScript and C# in the tutes and examples will just be syntax, which you should be able to pick up pretty quickly either way. You’re doing the same things, you’re just writing something slightly different to do them.

There are a few areas where you need to be more explicit with C# than with JS, like modifying struct data types, but as far as I can think that’s the only real down side and, to be honest, I personally prefer it that way.

JavaScript isn’t a separate language. JavaScript is just another name for UnityScript, which is not the same thing that everyone else calls JavaScript.

I have started with C#, but JS is same thing.
There are only few little differences if you’re making basics.

Now I’m using Java because it’s less writing.
But there are a lot more tutorials for C# as I know.

From my experience, I currently believe that Javascript is great for game code, and c# on the other hand, is better suited for framework and library code. With Javascript you don’t have to worry about inheritance or interfaces or anything like that. Js makes programming simpler and perhaps easier to read, so it’s great for game code (you know, like a bomb script or an enemy/player script). Now, c# always requires you to think about things like: “Okay, who is class B inheriting from”, which is fine and all for some things (frameworks, editor extensions, types that aren’t being serialized by unity, etc.) but simply unnecessary for game code as that is what prefabs are for.

So to make a long story short, learn both :slight_smile:

I agree. I much prefer C# to Unityscript.
I’ve used a lot of different engines proprietary languages which were actually quite nice and worked well, but in the end I think if you’re starting out why not start and learn a language that actually has other transferable real-world applications. C# is great and widely used in a lot of other applications other than Unity. On the flip-side, Unityscript could, maybe, possibly teach you the basics quicker, but I feel it leads to bad habits down the track. For example, a lot of Unityscript users would hardly ever use things like classes, namespaces, inheritance, etc because they don’t necessarily need to (not saying it’s not possible with USscript, extends, etc), whereas create a new script in C# and you’ve already had your first introduction to a class deriving from the Monobehaviour class.

As with anything, there’s pros and cons, UScript is fine don’t get me wrong, but I feel it’s like me knowing languages like Blitzmax and Monkey, fine to play around with or for full-time indie development, but if you’re looking to expand your programming career in the future, I feel it would pay off to learn some more commonly-used languages.

…plus I have a beef with ‘var’ :stuck_out_tongue:

Being a C# developer in Unity for the last 3-ish years I think it’s obvious which way I lean. Polymorphism and object inheritance is a huge deal in game development, especially when dealing with systems like object managers/factories, game states, and anything that remotely resembles a strategy pattern. It helps to create more flexibility at run time, where it should be while preventing duplicate code and lowers the cost of refactoring and maintenance. Not to mention if you write logic in C# in a modular fashion you aren’t locked into Unity only, it can be used externally in other frameworks.

Unityscript can be a trap for newer developers because of the fact that you can just throw in un-typed variables all willy-nilly. That might seem like a good thing at first, but wait until you start getting run time bugs because a variable is of a different type than you think it is. This flexibility also comes at a performance cost, hence the optimization of #pragma strict. If you write UnityScript it is ONLY usable in Unity, since it is an internal language.

Also, you might think about some of the more basic things that UnityScript won’t do, like pass a variable to a function by reference. Unless things have changed.

The situation that most tutorials are in Unity/JavaScript but C# is more complete is a real problem. When I started with Unity not so long ago I was asking the same question because I have quite a bit of experience with Java and C# is pretty close to that. You need to find some good tutorials on C# in Unity, and I recommend 3DMotive although there are probably others. Then try to convert some simple examples in JavaScript to C# to see where the differences lie. Even though JavaScript does not seem to use classes like C#, it actually does. The script itself defines the class without your having to write class Whatever at the top. At the moment I can switch pretty easily between them so can access all available tutorial material, including Sue Blackman’s book which I’m working through at the moment. I haven’t translated that to C# (yet) though.

Hey guys, thank you very much for your input! I really appreciate it. I think for the time being I’m going to roll with C# but I think I may try to pick up JS down the road. Thanks again :slight_smile:

this is wrong: Loading...

sorry for doublepost. forum is quirky today for me.

Yeah, just to reinforce what others said: C# is industry standard with massive code base and UnityScript is just Unity - you won’t be able to use any of the JavaScript stuff you find on web because it’s not quite the same thing as UnityScript and it will restrain you to only what Unity API provides. Plus C# is object oriented like languages you know. Definitely go with C#.