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.

You must be logged in to upload images. Register

Discussion

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

    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

    #
    1
    Dec 12, 2011 at 5:26 pm
    • David Lee
      Posts: 11

      ober = over

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

      #
      1.1
      Dec 12, 2011 at 5:28 pm
    • 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

      #
      1.2
      Dec 12, 2011 at 5:54 pm
      • David Lee
        Posts: 11

        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

        #
        Dec 12, 2011 at 6:36 pm
      • Posts: 45

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

        #
        Dec 13, 2011 at 12:07 am
      • 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.”.

        #
        Dec 13, 2011 at 4:03 am
  2. David Lee
    Posts: 11

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

    thanks
    sasbian

    #
    2
    Dec 14, 2011 at 7:29 am
  3. Posts: 45

    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

    #
    3
    Dec 20, 2011 at 1:33 am
  4. Posts: 109

    Hey Jeremy,

    Sure thing! They’re called operators, and here’s a quick overview of what they do: http://pastebin.com/LUqWDjgu

    Hope this helped!
    -Patrick

    #
    4
    Dec 20, 2011 at 10:12 am
    • Posts: 45

      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

      #
      4.1
      Dec 20, 2011 at 10:43 pm
      • 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

        #
        Dec 21, 2011 at 4:11 am
      • Posts: 45

        Now THAT is a great explanation. Thank you sir!

        Jeremy

        #
        Dec 21, 2011 at 6:11 pm
  5. Posts: 26

    Wow, nice tutorial, Patrick! But I got one questions:
    1. I see you have a mac and your using monodevelop, and I was wondering how do you open it on your mac.

    Thanks Patrick, for this nice tutorial!

    P.S Here’s a VERY good link about scripting for noobs!: http://www.unityscript.com/lessons1/basics.php

    -Jnick

    #
    5
    Jul 19, 2012 at 2:04 pm
  6. 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

    #
    6
    Mar 25, 2013 at 6:39 pm
    • Posts: 147

      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

      #
      6.1
      Mar 26, 2013 at 1:31 am

Leave a Comment

You must be logged in to post a comment.