Book Image

Learning Unity 2D Game Development by Example

By : Venita Pereira
Book Image

Learning Unity 2D Game Development by Example

By: Venita Pereira

Overview of this book

<p>If you are looking for a guide to create 2D games using Unity, look no further. With this book, you will learn all the essentials of 2D game development by creating five real-world games in a step-by-step manner throughout the course of this book.</p> <p>Starting with a blank scene, you will learn all about the new Unity 2D toolset, which will enable you to bring your scene to life. You will create characters, make them move, create some enemies, and then write code to destroy them. After figuring out all the necessities of creating a game, this book will then assist you in making several different games: games with collision, parallax scrolling, Box2D, and more.</p> <p>By the end of this book, you will not only have created several small games, but you will also have the opportunity to put all your new-found knowledge into creating and deploying a larger, full game.</p>
Table of Contents (17 chapters)
Learning Unity 2D Game Development by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Hello world


When creating our first code, the tradition is to create "hello world" as our very first code. To do this, we need to do the following:

  1. In MonoDevelop, within the file we have just created and named HelloWorld, we create a variable under #pragma strict.

  2. To create a variable, we declare it by typing var.

  3. Follow this by typing greeting—the name of the variable.

  4. Then, we use a colon : to declare the type that the variable will be using, followed by typing out the string type String as we want to store text in our variable. We need to ensure that we use String with an uppercase S; otherwise, we will get an error.

  5. We then use the assignment operator = followed by the text "Hello World!" with quotes to assign the variable with text and thus initialize it.

  6. We always finish a line with a semicolon ;.

  7. We then use the UnityScript function print by typing out "print" to print out our text, and we pass it the variable we just created so that it will print the information stored within the variable...