Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Javascript and C#

Discussion in 'Scripting' started by kalacia, Apr 8, 2016.

  1. kalacia

    kalacia

    Joined:
    Apr 25, 2015
    Posts:
    7
    Hey guys,

    Its probably been asked a million times, so apologies in advance.


    Ive been building simple form based games in a browser for a while, using it as a means to learn JavaScript, PHP, AJAX and SQL. I want to try unity so i dont need a web connection to play games, Ive kept trying to get my feet wet in unity for a while. But keep getting stuck on the scripting language, most online tutorials i see are in C#. The unity examples i download are in C#.

    I know C# can call upon the .NET structure, it being C# which is a huge benefit. But other than that Is C# that much better than JS? or am i just failing at Google.

    Any links or help would be great. As its the scripting functionality that i'm hitting a wall with.

    Thanks
     
  2. Philip-Rowlands

    Philip-Rowlands

    Joined:
    May 13, 2013
    Posts:
    353
    This does come up quite a lot. However, the "JS" that Unity uses isn't actually JavaScript, but a customised variation of it, and it doesn't entirely map back to normal JavaScript - so, anything you know in JS won't necessarily translate to UnityScript.

    With C#, this isn't the case at all - it's plain, regular C#. Anything you find on the web regarding C# will transfer over.
     
  3. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    C# is a more strict language than JavaScript, which it's easier to debug since you'll get warnings and exceptions whith ambiguous situations that would go unnoticed with more permissive language.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    This is an understatement. Unity's "JavaScript" (dubbed UnityScript by the community) is nothing like JavaScript. Objects are OOP objects, not prototype-based objects, so you can't add properties to objects after they're created. There's no DOM. You can't redefine methods. You have to care about the type of numbers (integer vs. float). Etc. etc.

    It's simply another .NET language, with syntax that's made to look like JS. It's a lot closer to C# than to JavaScript, as they're running on the same runtime under the hood.

    The language is also being slowly fazed out by Unity - the last version of MonoDevelop does not support UnityScript, the examples used by Unity are now all being written in C#.

    UnityScript is only used in Unity - last time I saw stats, it was something like 20-30% of Unity's users. C# is used by a lot of people. If you have a language-specific question about C#, there's answers on the entire internet, including places like StackOverflow. UnityScript questions can be posed to a small subset of Unity users.

    Finally, UnityScript is kinda bad. There's some special features that's added to it to make it closer to JS - like a custom array type and the ability to turn off the "strict" mode, which means that the compiler won't do type checks. All of these features are horrible, as they both make your code slower, and more prone to bugs.

    So use C#. Unity should kill UnityScript, as it has an overall negative value for the engine.
     
  5. kalacia

    kalacia

    Joined:
    Apr 25, 2015
    Posts:
    7
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    Note that if your end goal is to learn to use web technologies, Unity is probably not the best platform to do that in, for the reasons stated above. So if you want to learn, as you said, "JavaScript, PHP, AJAX and SQL", the only technlogy there that's relevant would be SQL, if you're making a Unity game using databases, which is not really necessary. If your dream is to be a web-based front-end developer, this isn't a good place to learn that.

    If your end goal on the other hand is to make games that can run in a browser, then Unity's a good platform. While the WebGL platform that you'll be publishing to is still a bit immature, it's how web games will be built in the future, as plugins are getting dropped by all of the major browsers.

    If your end goal is to simply learn to program, Unity's also a good platform. Note that writing code for Unity is in some ways fundamentally different from writing code for other platforms - but not in ways that makes it a bad platform for learning.
     
    kalacia and Philip-Rowlands like this.
  7. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Use C#.

    Microsoft announced a partnership with Unity last week. Unity is helping to shape the Future of .NET
     
  8. kalacia

    kalacia

    Joined:
    Apr 25, 2015
    Posts:
    7
    @Baste i just like to learn stuff. JS and web tech is usefull to my day job although not core to it. I do developement and platform support, so last line for customer issues, but first line for dev and platform issues.. So i tend to flutter between technogies as and when ii need to learn them. But right now, i want to learn something for me and I have too many ideas for games in my head and i want to get them out of my head into code.

    From what all you guys are saying it seems pretty clear that C# is the way to go.