A beginner’s intro to Scripting with JavaScript in Unity.

What is covered in this tutorial:
-Choosing the default Script Editor
-Creating a new Script
-Editing a Script
-Variables
-Function Update{}
-Viewing and Editing Variables in-editor
-Attaching script to a Game Object in the Scene
-”Playing” the Game

GSWU<>

You must be logged in to upload images. Register

Discussion

35 Responses to “Unity: Introduction to Scripting”
  1. Posts: 2

    I don’t know if this is just me but I’m having a linking issue for the download button on this page… All the other ones work just fine. Just trying to help out with your launch. Great and exiting stuff guys!

    Oh and…First!

    #
    1
    Nov 30, 2011 at 12:38 pm
  2. Posts: 34

    Yup! The URL was missing an “H”. ;) Fixed and should work.

    #
    2
    Nov 30, 2011 at 12:42 pm
  3. Posts: 2

    …And it works! Job well done citizen!

    #
    3
    Nov 30, 2011 at 1:00 pm
  4. Posts: 2

    Definitely can’t wait for more of these!!! I’ve been using Blender Cookie for a little while, definitely going citizen soon!!!

    #
    4
    Nov 30, 2011 at 4:17 pm
  5. Himal Bissessar
    Posts: 2

    Wow finally, I can get tutorials for unity.. I’m only 15 years, grade 9.. And this site is helping me, Thanks Wes burke :) .. So far so good.

    #
    5
    Nov 30, 2011 at 11:50 pm
  6. Himal Bissessar
    Posts: 2

    Sorry that was suppose to be a happy face :)

    #
    6
    Nov 30, 2011 at 11:53 pm
  7. Posts: 12

    Grats on the sites release, looking forward to more Tutorials!
    How long will the GSWU Series supposed to last? 1-15 Parts? :) Either way GREAT WORK! <3

    #
    7
    Dec 2, 2011 at 6:46 pm
  8. Posts: 2

    Excellent intro series to Unity, looking forward to watching more!

    #
    8
    Dec 6, 2011 at 11:51 pm
  9. I’ve got 3.5.0 beta3 I can’t find UniSiTE

    #
    9
    Dec 9, 2011 at 4:04 pm
    • Gabriel Williams
      Posts: 37

      Hi Necrorrr- you are mostly likely missing it because you are using a beta version of Unity, which is bound to have some missing/glitched/half-baked issues.

      Especially if you are just starting with Unity, it’s probably best to use the latest “stable” version of the engine :) That should fix the problem!

      #
      9.1
      Dec 10, 2011 at 2:27 am
  10. Posts: 45

    What are you games on the Apple site?!

    Jeremy Deighan

    #
    10
    Dec 9, 2011 at 8:49 pm
  11. Posts: 1

    This is awesome, i worked in flash and i´m very good at ActionScript 3, i have for at least 2 – 3 month looking for a fun way to learn javaScript. This is it

    GREAT !!

    #
    11
    Dec 21, 2011 at 6:19 am
  12. Posts: 3

    umm im not sure why, maybe its just cuz i downloaded unity 3.5 on my Mac
    but when i try to look for “UnisciTe” i dont have it.
    inside my “Unity” folder in my applications, i have “Documentation, documentation.html, MonoDevelop, Standard Packages, Unitron, Unity, and Unity Bug Reporter”

    in “Documentation and Standard packages” i couldnt find any folders such as “Data, and tools”
    … and in the folders that were there i couldnt find any that had to do with Uniscite

    #
    12
    Mar 12, 2012 at 9:38 pm
    • Posts: 1

      I think uniscite is only for Windows. I tried looking it up and couldn’t find it.

      #
      12.1
      Oct 11, 2012 at 4:44 pm
      • Posts: 268

        Hi Dan! What you are looking for is “Unitron”, on the Mac side of things- thanks for bringing that up!

        #
        Oct 11, 2012 at 7:31 pm
  13. kareyu
    Posts: 3

    Hey, very cool tutorial :)
    but my camera doesn’t move over to the new location like yours. Your camera move looks animated, my camera only disappears at the previous location and appears at the new location in the next moment…

    #
    13
    Apr 6, 2012 at 8:15 am
    • kareyu
      Posts: 3

      oh, i have found my mistake.
      i wrote it into the function start section, so unity transforms the camera exactly at the start.
      Of course it works into the function update section :)
      by the way thank you for your great tutorials and sorry for my english :D

      #
      13.1
      Apr 6, 2012 at 8:23 am
      • Posts: 268

        Glad you found the fix, and thanks! :D

        #
        Apr 11, 2012 at 12:56 pm
  14. Posts: 3

    Honestly, I’m pretty sure I should learn Blender more. Unity is very fun for me, I’ve had some background in scripting because I used to use Lua a lot. The best thing I can make in Blender, with a reference image, is a butter-knife. Decent texture and metallic material.

    #
    14
    Apr 8, 2012 at 6:19 pm
  15. Posts: 14

    I would rather learn how to use C#, are they really different ?

    #
    15
    Dec 17, 2012 at 5:43 pm
    • Posts: 147

      Cool, C# is a faster script and is usually better in the end, but harder to learn than javascript, and can be cumbersome to work with at times.
      Unfortunately I am horrible with C#, Gabriel or Wes may be able to make a series on it at some point though :)
      -Alex

      #
      15.1
      Dec 18, 2012 at 4:11 pm
  16. Posts: 14

    I was trying to slow the thePlayerSpeed way down. To decimals like .1, .5, etc. and it doesn’t seem to slow down lower than 1. Is there a special way to make unity understand numbers less than 1 but greater than 0 ?

    #
    16
    Dec 18, 2012 at 12:41 pm
    • Posts: 147

      it should handle decimals fine, make sure you are using a float variable and not limiting it anywhere else in your script, you can also use multipliers like finalSpeed = speed/10 if need be.
      -Alex

      #
      16.1
      Dec 18, 2012 at 4:09 pm
  17. Posts: 4

    everything i try does not work how do you get uniscite on mac???? follow your tutorials in mono and in unitron i typed exactly as you did and all i get is error message saying cant play till script is fixed please help this is only thing hindering me in starting to create a game

    #
    17
    Jan 11, 2013 at 12:54 pm
    • Posts: 147

      uniscite is no different to mono in that sense, check the console window and it will be showing an error with the script,
      -Alex

      #
      17.1
      Jan 11, 2013 at 5:05 pm
      • Posts: 4

        so is uniscite the same as unitron then?
        -chris

        #
        Jan 12, 2013 at 12:33 am
    • Posts: 147

      Pretty much, I write scripts in notepad sometimes, it really doesn’t matter what you use.
      -Alex

      #
      17.2
      Jan 13, 2013 at 1:03 am
    • Posts: 268

      As Alex said, uniscite/unitron/notepad- all the same at the core, will not effect how your code works. Give that error console a look, and let us know what errors it shows?

      #
      17.3
      Jan 13, 2013 at 8:21 pm
      • Posts: 4

        yay thanks guys i finaly managed to make a cube rotate lol do you know of any good sites for researching java script as im new to all this stuff im better at the arts design side of this and anything that can help me to better myself would be greatly appreciated.

        Peace
        -Wolf

        #
        Jan 14, 2013 at 6:34 am
      • Posts: 268

        The standard Unity reference docs are great!
        http://docs.unity3d.com/Documentation/ScriptReference/index.html

        #
        Jan 20, 2013 at 8:48 pm
  18. mustafa
    Posts: 1

    thanks for tutorial and easy to learn but I had some script issue , am using MAC and when I want to use the UniSciTE file I couldnt find it and I was kipping follow you tutorial and I hv done every thing and when I wanted to play it as game mode it says you have to fix the complier script and heres my codes
    var forwardSpeed : float = 3;
    var turnSpeed ; float = 2;
    function Update ()
    {
    //this is the forward speed that will actually happen
    var forwardMoveAmount = Input.GetAxis(“Vertical”)*forwardSpeed;

    //actual turn amount
    var turnAmount = Input.GetAxis(“Horizontal”)*turnSpeed;

    transform.Rotate(0,turnAmount,0);
    }

    and it says on the burrem of the unity Assets/Control Script.js(14,45): BCE0051: Operator ‘*’ cannot be used with a left hand side of type ‘float’ and a right hand side of type ‘Object’.
    Assets/Control Script.js(7,17): BCE0049: Expression ‘float’ cannot be assigned to.
    also when I want to put turnAmout it says not match
    I need help with that to fix it

    #
    18
    Feb 24, 2013 at 6:57 pm
    • Posts: 268

      Hi Mustafa,

      UniSciTE doesn’t exist for Mac- don’t worry, you can just leave that alone and use the default MonoDevelop tool. Heck, you could use Notepad, and it wouldn’t matter :)

      Also, you need to declare the type of variable that “forwardMoveAmount” is, like you did in your upper variables.

      Also-also, your “var turnSpeed” line is using a semicolon, where it should use a colon.

      Give those a check, then see if things are still broken! :)

      #
      18.1
      Feb 25, 2013 at 1:56 pm
  19. Ram
    Posts: 1

    I’m new to scripting, I typed everything like you did but it only moves my camera once and stops there.
    Not sure how to fix it.

    #
    19
    Mar 14, 2013 at 7:59 pm
    • Posts: 268

      Hi Ram- first and foremost, drop in some “Debug.Log()” commands. They’ll let you see exactly what your script is doing, and when, and where it stops/breaks.

      Second, double check and walk through the video carefully, makes sure you have everything exactly the same. Citizen members are able to download the source files, if that helps.

      #
      19.1
      Mar 14, 2013 at 8:20 pm

Leave a Comment

You must be logged in to post a comment.