C# or Javascript

Lets say you’re new to programming. And you want to create games in Unity. Would you try to master C# or Javascript, or try to learn a little of both?

Basically what is the best language to learn for Unity? I’ve been learning Javascript because I thought that was what’s best for Unity but Im finding a lot of C# users. Is C# also the primary?

JavaScript is easier, therefore easier to find example code for.

C# is very worthwhile learning, though. It has advantages to know it way beyond Unity and game development. It’s always nice, should game development projects not bring much money, to list in your resume you have “x years as a C# developer”.

I’m not sure why people believe that JavaScript is easier. It depends a lot on your background, and how you prefer to learn (there’s a lot more resources for learning C# than learning the special JavaScript dialect that Unity uses).

According to a poll I created a while back, it also seems that C# is a little more popular amongst the forum population :wink:

See also: Boo, C# and JavaScript in Unity - Experiences and Opinions

Hey nice Poll Jashan! That pretty much answers my question. I wish this forum had a “Beginner’s Questions” section. Because I have TONS of questions about Unity and Scripting in Javascrpt and I don’t like cluttering Unity’s forum’s Script section with all my noobie questions. I also don’t want to use a 3rd party forum website. Especially since they don’t relate to Unity. But anyway. Thanks for the feedback!

UnityScript is great, but so is C#, I suggest learning both, :wink: I plan to, once I become a master of UnityScript, I have a book on C# so this summer I plan to read. And the cool thing is lots of stuff from on works on the other.

This statement right here.
Aside from a few syntax changes C# is a better, more structured language with better OOP features.

And aside from the sheer fact that it has full Intellisense in your code editor, just that alone in my opinion even makes it ‘easier’ than Javascript. I hate working in Javascript/UnityScript, mainly because of the intellisense, and because of the inability to easily reference other classes and types in your code.

So my vote goes 100% for C#, there really are so many reasons to learn it over Javascript, while Javascript in my opinion doesn’t offer any.

Once you understand C#, the syntax differences are quite easy to pickup. There are also a couple of free code converters out there. So if you’re not sure how to convert something use it and look at the changes, there are not many.

Meltdown,

Yes, I’ve been going over C# all day today. Converting my current project from JS to C# and I can see how C# really isn’t as difficult to learn as I thought. Unfortunately I’ve run into a few roadblocks in the conversion process but its all a learning experience.

Haha, you beat me to my previous statement. I’ll look for the code converters you mentioned right now!

Teriander if you have any problems in the conversion post in the scripting forum in I’ll be happy to help you out :stuck_out_tongue:

This is the one I used by the way…
http://www.m2h.nl/files/js_to_c.php

Also what editor are you using for your code?

Hey Meltdown! Sorry for the late reply. I’ve been stuck on trying to recode my last page and haven’t looked at the forum in awhile.

Your assistance would be fantastic! Im using MonoDevelop

Basically my problem is getting the the variables that were able to find GUI game object text via “GameObject.Find” to work in C#. It worked in my JavaScript perfectly, but I can’t figure the right format to work for C#. I did try the code coverter you linked me to, saw that site earlier in my search. But it didn’t solve my code problem. If you’d like to take a look at the working version I have in JavaScript here is it. ( Cleaned it up to the section where my problem lies):

function Start () {

        // Get Component to display Advisor's Icon Text
	textEnemeyIntel = GameObject.Find ("GUI_Text_Enemy_Intel").GetComponent (GUIText);
	textUnitsManagement = GameObject.Find ("GUI_Text_Units_Management").GetComponent (GUIText);
	textBudgetManagement = GameObject.Find ("GUI_Text_Budget_Management").GetComponent (GUIText);
	
        // Display Advisor's Icon Text
	textEnemeyIntel.text = "Enemy Intl";
	textUnitsManagement.text = "Units \n "  +  "Management";
	textBudgetManagement.text = "Budget \n" +  "Management";
	
}

Basically if you created a new scene and then created 3 GUI Texts by going to GameObject >> Create Other > GUI Text.
Name them:
GUI_Text_Enemy_Intel
GUI_Text_Units_Management
GUI_Text_Budget_Management

Link your JS to an empty game object and then play. You should see all three of your GUI text display text. If you do, and you know how to convert this to C#, that would be awesome!

Its 1am here right now so Im about to crash, if you have time to review this issue please let me know. Till then I’ll continue my research and testing tomorrow. Thanks Meltdown!

Just change the round brackets to <> brackets on GetComponent… and add the () at the end.

function Start () {

        // Get Component to display Advisor's Icon Text
	textEnemeyIntel = GameObject.Find("GUI_Text_Enemy_Intel").GetComponent<GUIText>();
	textUnitsManagement = GameObject.Find("GUI_Text_Units_Management").GetComponent<GUIText>();
	textBudgetManagement = GameObject.Find("GUI_Text_Budget_Management").GetComponent<GUIText>();
	
        // Display Advisor's Icon Text
	textEnemeyIntel.text = "Enemy Intl";
	textUnitsManagement.text = "Units \n "  +  "Management";
	textBudgetManagement.text = "Budget \n" +  "Management";
	
}

MonoDevelop could be the best IDE to use for UnityScript, but for C# there is a better one ― Visual Studio (even its free C# Express version).

The killer-feature is error highlighting:

The same code written in MonoDevelop looks absolutely normal, you have to compile it to see the errors.

Shame MS does not make Visual Studio for Mac :stuck_out_tongue:

I LOVE Visual Studio.

BTW on the why people consider JavaScript/UnityScript easier: it’s in large part it’s lack of structure and how it’s not as strict (unless you use #Pragma strict) making it easier for people new to programming to learn. An expert programmer would likely find it “easier” to use C# since its structure makes it harder to create accidental bugs with silly things like forgetting to declare a variable.

So I still stand by my “UnityScript is easier” but guess got to add the modifier “but it’s also easier to create buggy code with it.”

+1

I switched to C# early on after deciding to learn UnityScript, and it took a while to get used to the stricter coding. Always forgetting to declare variable, it wouldn’t automatically turn an int into a string, etc etc. But I’m glad I did, it is a lot easier to find where your code isn’t working with C#.

+1

I love when Visual Studio and C# protect me from shooting myself in the leg.

This 100x. I can be quite confident going back to unity that my code will compile without issue because visual studio is so proactive on informing you of coding mistakes. If only it would solve my logic mistakes. :stuck_out_tongue:

Alex,

Error highlighting isn’t on MonoDevelop? Are you sure? Because last night when I started the C# conversion, MonoDevelop was giving me the same red wavy-line under the code that had errors. The mouse-over error report might not have been there, if that’s what you’re talking about. I’ll have to double check.

But anyway if you guys recommend I use Visual Studio I’ll look into using this instead.

Meltdown,

Thanks for showing me the script fix for my problem! I’ll try this tonight when I get off work. Much appreciated!!

MonoDevelop checks syntax, VS verifies semantics too. Write the code above in MonoDevelop and you’ll see no wavy lines.

I use C# because I’m a .NET developer, but there’s no real advantage to either.

However, C# does get visual studio which is really nice - especially if you have the resharper addon.

I’d say learning C# for outside of Unity would be a good idea too, C# is becoming a widespread language fast(According to Tiobe, it went from the #6 used language to #3 in under a year, surpassing C++)