Unity: Introduction to Scripting

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

Leave Comment

Discussion

36 Responses to “Unity: Introduction to Scripting”
  1. Posts: 2
    Henry Grimes says:

    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!

  2. Posts: 57
    Wes Burke says:

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

  3. Posts: 2
    Joshua Healy says:

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

  4. Posts: 2
    Himal Bissessar says:

    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. Posts: 2
    Himal Bissessar says:

    Sorry that was suppose to be a happy face :)

  6. Posts: 12
    Jerry Miller says:

    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. Posts: 2
    dreamsgate says:

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

    • Posts: 37
      Gabriel Williams says:

      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!

  8. Posts: 1
    ufoalf300 says:

    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 !!

  9. 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

    • Posts: 3
      Daniel Lopez says:

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

      • Posts: 268

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

  10. Posts: 3
    kareyu says:

    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…

    • Posts: 3
      kareyu says:

      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

  11. Posts: 3
    Mark LaBarr says:

    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.

    • Posts: 158
      Metalix says:

      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

  12. Posts: 16

    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 ?

    • Posts: 158
      Metalix says:

      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

  13. 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

    • Posts: 158
      Metalix says:

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

    • Posts: 158
      Metalix says:

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

    • 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?

  14. Posts: 1
    mustafa says:

    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

    • 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! :)

  15. Posts: 1
    Ram says:

    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.

    • 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.

  16. Posts: 1

    The UniScriTE no longer exists on my version I have Unitron and you can highlight and look stuff up by clicking the big green magnifying glass top left.of the UI.

Leave a Comment

You must be logged in to post a comment.