Introduction to scripting in Unity

In this Unity video tutorial we’ll be going over some of the basics of scripting in Unity. Building on what was learned from the Getting Started Videos.

First I’ll talk a bit about the differences between the three available ‘flavors’ of UnityScript (JavaScript, C# and Boo), and will then proceed to write two basic JavaScript and C# scripts to move a cube around.

Leave Comment

Discussion

16 Responses to “Introduction to scripting in Unity”
  1. Posts: 11
    David Lee says:

    first to comment :D :D

    Good job on the tutorial.

    How much better or worse is it to use boo rather than java or c#? And what would be the advantages of any of those ober the other?

    (If it’s in the video, sorry, my bandwidth is out and cant download right now. I will though as soon as it (bandwidth) picks back up)

    thanks,
    Sasbian

    • Posts: 11
      David Lee says:

      ober = over

      and i did get to see a little of the tutorial though.

    • Posts: 109

      I’d give you a cookie for being first, but you said Java instead of JavaScript, which is a … touchy subject, to some. ;) *eats cookie himself*
      Anyway, both questions are answered in a bit of detail in the video, but in short, no language is superior to the other, with the exception of some advanced stuff being only possible in C# (I.e.: reflection, C/C++/Objective-C calling). That said though, if you’re fairly new to programming in general I would recommend -against- using Boo. Reason being is that very few people actually use it, and thus most code examples, snippets, questions and answers are in JS and/ or C#. (The Unity documentation always provides examples for all 3 languages though.)
      However, if you feel comfortable using Boo and you have no trouble translating “var target:Transform” to “public target as Transform”, then of course feel free to use it.
      I should probably also point out that any combination languages can be used throughout your project and even on the same objects. Since it’s all just a syntaxical flavor of the same underlying language (UnityScript), they can still all communicate with each other, calling functions, getting and setting variables, etc.

      Hope you’ll enjoy the tutorial!
      -Patrick

      • Posts: 11
        David Lee says:

        thank you. that was very helpful. reflection is one of the things that I want to do in my current project. I am new to programming in general so I think that I will start off with learning a bit of c# and keeping an eye on boo (for some reason It seems easer to me). And that was a very good answer to the question.

        thanks,
        Sasbian

      • Posts: 46

        What is reflection? A programming term or the actually reflecting something in the game?

      • Posts: 109

        Oh, Jeremy raises a good point! I meant the programming term reflection. From Wikipedia: “In computer science, reflection is the process by which a computer program can observe (do type introspection) and modify its own structure and behavior at runtime.”.

  2. Posts: 11
    David Lee says:

    ok … I took that as actual reflection, lol. Thanks for clearing that up for me.

    thanks
    sasbian

  3. Posts: 46

    Can you explain the differences in using – + = -= += == && etc? Or know of a good reference for those? Not sure why it’s not “transform.position.x + speed”.

    Other than that I thought it was a great tutorial. I should have watched this first! lol

    Jeremy

    • Posts: 46

      That clarifies things up a bit. I’ll do some more research because I still don’t understand the difference of + versus += . Thanks for the link and the name!

      Jeremy

      • Posts: 109

        Ah sorry, I could’ve been a bit clearer on that. Basically it comes down to this:

        + is always used in a syntax similar to “x = a + b”, where the result of a+b is stored in another variable.
        += is used to add something to a variable and store the result in that same variable. For example “x += a”. This is the same as saying “x = x + a”.

        Think of it this way: += means “add to, and assign the result to”. =)

        -Patrick

  4. Posts: 1

    Hey patrick!! As im new to the unity world im trying to build a simple hover craft racing.
    Game ive got the models of crafts an a place to race i need help with writing a script to make it come alive. For now a simple forward back left right an idle. Or should i say hover idling will do please can u get back to me on this. Sad face. Progression is a must gamer for life lool. Thanks

    • Posts: 158
      Metalix says:

      I believe the making a game in 30 minutes on Unity Cookie will be your best option :)
      Also we will be taking a look at using mecanim which would allow you to do some more advanced movements as well.
      -Alex

  5. Posts: 1
    mccor013 says:

    Hi everyone, new citizen here and I want to know why Boo is under appreciated in the Unity scripting community. I am a beginner python programmer and obviously Boo would be an ideal syntax for me to use. Because Boo is not used as much as Unityscript or C#, this results in a lack of Boo tutorials and documentation.

    I would also like to know if anyone knows if Unity 5 will be keeping Boo, my thoughts are they will, but I would love to see more information from them and from the community. Also, I would love to the CG Cookie community provide Boo tutorials as it would provide a great service to a smaller demographic that is clearly under appreciated. It concerns me when 1/3 of the potential scripting landscape is almost being ignored especially when they are, as put by the instructor in this video, all the same language under the hood so to speak. I really like the content i’ve been seeing on CGC so far, many thanks.

Leave a Comment

You must be logged in to post a comment.