It's all Greek to me

First, we created a JavaScript Script. Unity Scripts are written in three languages that are somewhat like English: JavaScript, C#, and Boo. Of these, JavaScript and C# are the two most commonly used languages in Unity. You may have already dabbled in JavaScript if you've tried your hand at web development. Unity's version of JavaScript (called "UnityScript") is a bit different because it talks about Unity-related things and runs much faster than your father's JavaScript.

In this book, we'll use JavaScript because it's the simplest of the three languages to learn. For this reason, many of the online Unity scripting tutorials you'll find are also written in JavaScript.

Tip

Look Sharp

One major difference between JavaScript and C# is that C# is more formal, more rigidly structured, and more "strictly" typed. It's a bit like the difference between grabbing a milkshake at a greasy spoon with your best friend, and having high tea with the Queen of England; expect C# to constantly correct you on your table manners.

Among the advantages of a strictly-typed and structured language like C# is that it may be better suited to much larger projects, and with C# you tend to see fewer run-time errors—that is, problems that crop up while your game is running.

JavaScript is an excellent choice for beginner programmers, but many readers of previous editions have asked if this book could also include C# examples. From this point on, wherever you use JavaScript code, you'll find the completed and commented C# translation at the end of the chapter.

The first thing that we did was to write a line of code between two curly braces. I like to think of curly braces as delicious sandwich buns that group code together. The single lines of code are like the thin layers of salami or tomato in the sandwich. Above the curly braces is the description, or declaration, of the sandwich. It's like saying: We are now going to make a hoagie—top sandwich bun, yummy ingredients, bottom sandwich bun.

It's all Greek to me

In more technical, less sandwich terms, the area grouped by the buns is called a statement block. The layers between the buns are called statements. And the type of sandwich we're making, the Update sandwich, is known as a function.