Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Best language to learn for use with Unity?

Discussion in 'Scripting' started by Ghachii, Feb 26, 2009.

  1. Ghachii

    Ghachii

    Joined:
    Feb 26, 2009
    Posts:
    36
    Hi!

    Given that my scripting experience is limited, what would be the best language to learn for scripting in Unity? What do people find to be the easiest or most convenient? Is Unity more geared up for supporting one language over the others?

    Thanks?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Easiest is JavaScript if you are fresh.


    But C# is much better documented as it is an industrial standard language with ten tousands of pages and tutorials on the web. so this means on the long go it can save you time or if you intend to do a large project especially.

    unity javascript is not the regular javascript so you will have to mix in "common javascript" knowledge with unity. Unity JS is only an alternative language for the .net.
     
  3. ryanzec

    ryanzec

    Joined:
    Jun 10, 2008
    Posts:
    696
    I don't think Unity is geared to use one language over the other (but can't say for sure because I have yet to use it, waiting to the windows release) but I would recommend C# for a few reasons. One reason is like stated above, there is more documentation for it since C# seems like the main language for .NET (at least to me, when I see stuff about .NET, most of the time I see references to C# instead of the other .NET languages like VB, C++, etc...). Also learning C# for unity would would provide more general usefulness than learn Javascript for Unity since C# is use and many different area of programming(Web, Desktop Application, Game Development, etc...) and from what I have read the javascript that is used in unity is a modified version tailored to use .NET (I don't think is has an general purpose use outside of unity).

    Take a look at both languages and see what you feel more comfortable with and go with that as using a language that feels very akword to you just because other people say you should use it is not going to help you very much
     
  4. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    I do want to make a strong point for Boo, which gets overlooked too often. It has all the simplicity of JavaScript, the best syntax or all three languages and the power of C#. There's also enough documentation at the official homepage and a mailing list for everything else.

    Isn't it great to write the same code with half the characters as with C#. Programming should be elegant!
     
  5. ryanzec

    ryanzec

    Joined:
    Jun 10, 2008
    Posts:
    696
    To each its own. Some people I know find VB code much more elegant than C# but to me VB code is so inelegant.
     
  6. Omega

    Omega

    Joined:
    Jul 31, 2007
    Posts:
    125
    For a beginner, I would strongly recommend UnityScript. Now, there have been wars over the name for quite some time, but it IS called UnityScript, not javascript. Any non-believers can go and find UnityScript.lang.dll for themselves in the Unity application package, but I digress. The point is that Unityscript is the best language for beginners. And I say this because it's simple, easy to learn, and powerful.

    1. Simple

    The reason UnityScript is simple is that it doesn't have all of the bloat that C# has. Newcomers don't need the fuss of "public static void Main", etc., and all the extra code is confusing. Although it can be learned around and ignored, why should it even be there if it can't be used? Learning UnityScript from scratch, it took a very long time before I would have needed to even look at any of those lines. It's the equivalent of making wrapping all forum posts in [post]...[/post] mandatory; it is not only completely redundant, it is a monotonous task that should be handled by the machine that was created to perform monotonous tasks.

    The same goes for both variables and function/class definitions. To quote an article on smalltalk:
    Since UnityScript uses type inference to automatically determine the type of the variable when it is set, superfluous type declarations like the one above are not necessary, which is one less thing newbies need to learn. UnityScript is also dynamically typed, so the user doesn't need to remember the type of every variable, or what type a function needs to return, and remember to explicitly cast variables that don't match up. And even that is making the very large assumption that they know what they're working with. It is doubtful that someone who is just learning programming is going to know the difference between a single, a double, a float, an int, and what signed even means, let alone care.

    Another thing that helps new users learn is the ability to test quickly. This rapid response time is how I learned my first "real" programming language, and one thing that Unity can and does proudly market. However, unlike in UnityScript, which generates a class automatically, a C# class name must match the file name, an irritant that I have come across many times. New users are more susceptible to this because, and I speak from experience, they may or may not know what a script is going to turn into, leading to having to rename it in multiple places down the road. Besides, the default also always has to be renamed, so it cannot be completely ignored even by experienced programmers.


    2. Easy to Learn

    UnityScript is, overall, easier to learn then C#, even when not including all the extra "rules" mentioned above. Most of the examples in the official Unity Documentation are written for UnityScript, not C#, requiring the user to translate the examples into C#. For and experienced programmer, it is not a problem. But for one who is learning programming, it can be a very large problem.

    More generic examples are also not hard to come by. Although C# is more widely used, UnityScript has quite a few examples for one to learn from, but they aren't filed under "javascript". The language to look for is Microsoft's JScript.NET, which, like UnityScript, is an implementation of javascript that has been seriously tweaked for the .NET environment. Although some have claimed that they are not related, some examples from JScript.NET can be directly copied for use with Unity, unlike regular "javascript". When combined with the excellent Unity Docs, one has language docs and API docs, whereas the C# "benefits" leave one with language docs, and detailed examples of how do do things that have little to no relation with Unity.


    3. Powerful

    UnityScript is, actually, quite powerful. It's extensions to "common" javascript gives it almost all the power of C#, which is more than enough for any beginner. From my experience, it is not possible for a beginner to exceed the capabilities of UnityScript. The only point it would become a problem is if they made a mistake, in which case C# wouldn't help. In fact, it might actually make it worse, since there are more things to keep track of. Good coding practices are easier to learn and maintain in simpler environments.

    Also, Adrian mentioned Boo. Boo is a relatively obscure language that is often under-appreciated, possessing all the benefits of UnityScript, and then some. In fact, the UnityScript language itself was written in Boo. However, Boo, which is based on Python, rather than C, is very different from both C# and UnityScript, despite all three running on the same runtime. This is the benefit to using UnityScript over Boo, as UnityScript is so similar to C#, learning the "powerful" language is much easier, whereas Boo generally doesn't mingle anywhere near as well. Boo also shares the same documentation problem as C#, which is amplified by its obscurity and lack of widespread use.


    All in all, all three languages do the same thing. They all use the same commands to produce the same result, they are all highly competent, and they all start language wars when mentioned. However, for a beginner, UnityScript is the best language to learn first. It is simple enough to not confound, documented enough to not confuse, and powerful enough to not constrain. And, having taught myself UnityScript, I speak from experience.

    [Revision 1]

    I also speak at 2:14 am. My apologies for any mistakes, typos, or inaccuracies. And feel free to comment, I'm sure I overlooked at least a few things.

    Edit: like typos.
     
  7. rom

    rom

    Joined:
    Jul 2, 2006
    Posts:
    265
    I disagree with Omega on some philosophical grounds

    Style and Approach are more important than any language.

    One does not need to know the solution
    you just need to describe the problem with clarity,
    the solution will arise automatically from this.

    dynamic typing, gets confusing
    If you are compiling code mentally.
    So you will need constant feedback from the (computer) compiler.

    No matter which language you choose,
    you will quickly reach a barrier.
    This being ,
    your ability to comprehend complex hierarchical nonlinear systems.

    Although a language like javascript are easier to learn.
    The initial productivity soon falls by the way side as you have to mentally track your code.
    with more explicate assertions, you can "forget" what you have done, and move forward.

    Although there are many languages,
    they are all very similar in what they can achieve.

    Before trying to win an oscar (with you authorship)

    1. Learn basic data types. (This knowledge is universal yet finite)
    (void,bool,int,float,double,char etc)

    2. Learn what, public, private, static etc mean (This knowledge is universal yet finite)

    3. Learn some mathematics. (Keep this in constant development)

    4. Learn some Physics. (Keep this in constant development)

    5. Learn basic computational constructs. (This knowledge is universal yet finite)
    Iterators,Conditionals,etc

    6. Learn how to mentally construct an Object with properties and methods.
    interfaces in C# can help with this.
    property accessors,

    If you create structure before complexity,
    you will not have a script "get on top of you"
    as the logic become self contained (encapsulated)

    7. Choose a language that you will not need to "track mentally",
    I think C# is a good choice.

    8. Get a good IDE, to avoid too much typing.

    9. Read, Code, Read some more. All good things takes time.

    You will find, that there are really only a hand full of things to learn (not including Mathematics and Physics)
    to perform a computation task.

    Complexity arrises from creating hierarchical structures
    (inheritance and auxiliary referenced objects)

    Some of the paradigms offered in C# like properties
    promote non-linear approach to the computational task.

    look for the "root solution".
    be generic.
    This will create leverage down the line.

    Try to understand this statement :
    Code (csharp):
    1.  
    2. private DataType m_myData;
    3. public DataType myData {
    4.     get {
    5.         if(m_myData!=null) return m_myData;
    6.         // code to resolve null
    7.         // consider null reference cascade
    8.     }
    9.     set {
    10.         m_myData=value;
    11.         // code to propogate value delta in m_myData
    12.         // consider value reference cascade
    13.     }
    14. }
    15.  
    This is a mystical struct that can scale super symmetrically to any level.

    I think people who will not learn their "ABCs",
    should just stick to art :)
     
  8. Vern_Shurtz

    Vern_Shurtz

    Joined:
    Mar 6, 2009
    Posts:
    264
    Being a newby to scripting of any type and wanting to learn Unity 2.5, when it comes out, Omega's post seems most logical to me and is the approach I plan to take.

    Just my 2cents...
     
  9. 3dj

    3dj

    Joined:
    Mar 9, 2009
    Posts:
    5
    I'm with you.
    I have fumbled around with actionscript a bit, I'm hoping I can feel my way around Unity the way I did with Flash.

    -Jim
     
  10. pavlito

    pavlito

    Joined:
    Nov 27, 2007
    Posts:
    136
    I agree. When I first got Unity, browsing through documentation made me use UnityScript from the beginning.

    Having taken a project for college (C# finals) I decided to port my silly little game to C#.

    Man, did I spit blood! :)

    Now I'm completely used to C# (although I still need to learn a lot).
    Porting examples from UnityScript to C# is still annoying, but it's all about the syntax. Nothing more, nothing less.

    If you ask me, its the same as 'color' opposed to 'colour' or 'generalise' opposed to 'generalize'.

    If you type either word enough times, you'll end up using the one you typed the most. ;)

    On the other hand, I do kinda miss the actionScript-like code. In this project at least. My next project might as well be written in UnityScript.
     
  11. phuzzy

    phuzzy

    Joined:
    Feb 12, 2009
    Posts:
    31
    As with all of our choices in languages across the web universe (JavaScript, C#, PHP, ActionScript, etc.), it's a matter of preference. I'm running a development team for a Unity project right now where all of us are strong JavaScript/PHP programmers, so JavaScript made sense for us. Other arguments aside, it's a go-with-what-you-know approach that gets you to the deadline with the least amount of bloodshed. If C# is you and your team's forte, run with that.

    The one thing I will say is that it's not the language implementations that are tough to get your head around, it's the relative relationships of Game Objects, Components and Scripts within the Unity Hierarchy that take time to work out. The code is slave to that larger Hierarchy structure, which is more often than not the source of trouble, not the language you choose to code with.
     
  12. carbonization

    carbonization

    Joined:
    Mar 23, 2009
    Posts:
    37
    VB increases readability via verbosity
    Boo Python take the opposite approach, increasing readability by stripping down syntax.
    I personally find C# unnecessary as programming in the Unity environment is much different than the 'standard' programming environment, starting from the ground up with a main() function. Unity uses a very nonlinear programming environment, heavily decoupling scripts from each other. You rarely (if ever) even use a constructor! Game scripting lets the engine deal with the technicalities structure of the game, letting the scripter focus on the fun part: making the game come alive. C#, after all, is based heavily off of C++ and like Java, designed to significantly increase programming productivity while still allowing for full control and flexibility for writing software from the ground up.
     
  13. Diablohead

    Diablohead

    Joined:
    Feb 3, 2009
    Posts:
    47
    I'm new to coding and going with UnityScript/Javascript, I have never used javascript before but I am finding the code good to learn.

    I have used javascript based code but only for about a week so I understand the var's and if's quite easily and that helps.
     
  14. Charles Gill

    Charles Gill

    Joined:
    Aug 1, 2008
    Posts:
    142
    Higgy, a general overview of this question should probably be item #1 in the "Scripting forum FAQ".
     
  15. jackyallstar

    jackyallstar

    Joined:
    Sep 4, 2013
    Posts:
    2
    to clear out the name confusion and train all you newcomers for the better; let's stick with Unityscript indeed.

    Wikipedia tells you this:
    While "JavaScript" is merely a generic name and could refer to any one of many implementations of the ECMAScript specification, Unity's ".js" language doesn't even come close to conforming to that specification — nor does it try to. UnityScript is a proprietary language, and it doesn't follow any concrete specification; it is modified at the will of the Unity developers.

    The vast majority of JavaScript libraries you find will not work just by copying them into Unity. Unity's "JavaScript" is most similar to Microsoft's JScript.NET, although it is not quite identical. Thus, many believe the language Unity uses to be called "UnityScript" instead.

    Some people consider this to be "just semantics," but when people call what is properly UnityScript by the name "JavaScript," it becomes a lot harder to search the Internet for solutions and help with UnityScript. It's also quite a lot of trouble to put oneself through to continually specify whether one is referring to "real JavaScript" or "Unity's JavaScript." So, it's best to just stick with "JavaScript" for real JavaScript and "UnityScript" for Unity's language.


    i second this, all the way.

    to make a long story very short (in comparinson):

    if you are a newcomer in programming and just want to goof around, go for UnityScript like Omega said. it features easier out-of-the-box tools which can help you get somewhere faster when inexperienced. be advised that altough this language is a very strong dynamic tool and completely works as the Unity developers think it should be done, C# will give you more freedom to implement your code as you seem fit. as if you are a Unity developer you might say, but not really since you are using a engine instead of making your own;) altough Omega's reply is easier to understand, Rom is actually right and it might be better to first learn your ABC's in programming since it can get really unmanageable really fast if you are not experienced and very, as i like to say, deep...

    you first need to understand what OOP (Object-Oriented programming) is, how to create managable code, how to build complex features out of simple instructions encapsuled together, and even more things like Rom says in his post, before thinking about the difficulties of the language syntaxis themselves, or even mathmetical graphics.

    a good start is to start with learning OOP trough tutorials you can google for since this wil teach you a new way of thinking in concepts and let you see the similairities and differences between reality and virtual reality, which is essential for programming good code. it wil open your mind and make you look at your car or phone in a new way, for example. i'm sorry i cant hand out any tutorials because i cannot determine how easy you catch up on it, but keep searching for a tutorial that suits you and seems understandable. the best tip for looking for this i can give you is to look for one that makes references to physical objects you know, like lighters, beer or other common stuff. that way you can relate easier:)


    whatever you do, if you truly want to be able to create games; DO NOT GIVE UP! things are never as hard as they first seem, but without some good old fashioned sweat on your back, your thing you try to accomplish isn't that unique or noteworthy, and programming isnt that hard if you can grasp the basics. it's just ALOT:p