Beginner's Scripting Guide

Introduction
So, you want to be a scripter, eh? Well, you came to the right place. This tutorial introduces you to scripting with Unity, from any level of experience. (Note: This tutorial does require the ability to make a scene.) So, let's get started!

Basic JavaScript (Beginner)
Ok, so if you don't know what the 3rd line does, have a guess. ...Think you've got it? Good. It prints the words, "Hello, this is the first section!" to the console. How incredibly useless is that? Very.

Making something move
Ok, so you can figure what we're gonna do now. Create a new scene if you haven't already, and make a random cube/sphere, whatever. Just place it in front of the camera. Now, click on the 'Create' button in the 'Project' view, and select 'JavaScript'. Name it what you like Now, double-click on it, and wait. When MonoDevelop has loaded up the file, delete everything and type in the following: Ok, so basically is something that is used once every frame, which in our case is 1/30 of a second. More on that later. The curly braces are basically defining where the function begins and ends. The next thing to explain is the if statement. In our case it is So it's like English. Basically it's saying, "If I find that mouse button '0' (left mouse button) is down, I'll do this." Anyway, the code in the if is as follows: Plonk that in your if statement and SAVE YOUR FILE. Basically, what that is, is the Y co-ordinate of our object, and we added 1 to it. Now go back to Unity, and drag the script from the 'Project' view onto the sphere/cube etc. in the 'Hierachy' view. Press the play button at the top of the editor and left-click your mouse in the 'Game' view. Twice. If it moves, then your script works! Now exit the game and let's make this cube move down! Enter this on a new line OUTSIDE the if statement, but still in Update. You should know what that means now. It's just the right mouse button, not the left. The whole file should look like this. Feel free to edit this section/code as you please.

JavaScript vs. C# vs... seriously?
Now, I know wiki articles aren't meant to be biased, but this is just a statement of fact. Boo is the least popular choice for coding. C# is the most popular/beneficial, and JavaScript is good for beginners but second popular. (Results from the coding articles)

Boo
So, why use C# or JS? Why not Boo? Well Boo is a cousin of Python, which, although has a tidy syntax, is a bit confusing for JS/C# users. For example: It's not all bad though. If it's what you're used to, then it's fine.

C#
This is a decent 'language'. It's ALMOST the same as JS, but it uses 'public', and 'private' etc. An example of this is: Why this is the case is beyond me, but it's true.

Our pal, JavaScript
Nothing beats this for beginners, absolutely nothing. No more said.

Instantiating
Ok, well, don't bother guessing what that means if you are a newbie. (Refusing to say n0.0b :D) In a nutshell, that's what we're gonna be learning today. So, what exactly is instantiating? Basically, it's creating something. Ok, so let's start!

Making a 'Rigidbody' Appear
So, for starting, just create a cube. Don't move it, it's not worth bothering. Well, make sure the camera can see it Now, click on 'Component>Physics>Rigidbody' at the top of Unity while your cube is selected. This will make the cube a 'Rigidbody', which is, in essence, a physics object. Now, in the 'Project' view, right-click on a folder/in the view, and click 'Create > Prefab'. Name it whatever you like. For simplicity's sake I will call it 'FallingCube'. Drag the cube that is a Rigidbody from the 'Hierarchy' view on top of your new prefab, then let go. Now, you can delete the cube in the scene, but not the prefab. Moving on, let's script.

Coding The Instantiation
(Note: Like the rest of this tutorial, this is going to assume you know how to make a script and open the editor.) Ok, so in your script, let's use the 'Start' function to instantiate this object. Hmm? What? Error? Absolutely. We haven't said what we are instantiating. So let's do that. That should work with one last thing. Select the new SAVED (*hinthintnudgenudge*) script in the 'Project' view, and drag it onto the 'Main Camera' object in the 'Hierarchy' view. From there, select 'Main Camera', find your cube prefab (you know where that is now), and drag that into the 'Falling Cube: DRAG OBJECT HERE' bit in the 'Inspector' view. Being truthful, it actually says 'Falling Cube: (Transform)' instead of 'DRAG OBJECT HERE', but that is where you ar- I'll stop there, I don't want to insult your intelligence further. :3 Now press the big play button. I really hope this works for you, it did for me, and if you have errors or glitches etc. post it in the 'Discussion' area. Thanks!

Help, I need a Loop Guru!
If you find you want to loop (i.e. for your co-routines) but are not sure about what type of loop, you've come to the right place! Here are a list of useful example loops;

The for loop
Basic "for" loop; start value, end value, update expression (operator i increases on each update):

The for loop can also be used to iterate of the contents of collections (ie. lists and arrays)

The while loop
A 'while' loop in a co-routine: