Learn to Code by Making Games - The Complete Unity Developer

Game development & design made fun. Learn C# using Unity 4.6 & Unity 5. Your first 7 2D & 3D games for web & mobile.
4.6 (11,553 ratings) Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
100,846 students enrolled
$195
Take This Course
  • Lectures 303
  • Contents Video: 45.5 hours
    Other: 6 hours
  • Skill Level All Levels
  • Languages English, captions
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 9/2014 English Closed captions available

Course Description

The course is continually updated, a major improvement was made in Glitch Garden in March 2016, and over 30 new quiz questions were added in June 2016.

This is the online game development school that was a runaway success on Kickstarter. As a result there are English closed-captions throughout.

Learn how to create video games using Unity 3D, the free-to-use game development tool. We start super simple so you need no prior experience or Unity of coding! With our online tutorials, you'll be amazed what you can achieve.

Benefit from our world-class support from both other students, and Ben is on the forums regularly. Go on to build several games including a full 3D version of Pong with an online multiplayer scoreboard, and more.

You will have access to a course forum where you can discuss topics on a course-wide basis, or down to the individual video. Our thriving discussion forum will help you learn and share ideas with other students. Check out our reviews to see how people love this feature.

Unity 5: The first part of the course is taught in Unity 4. 6, as this is well established and stable. When you get to Bowlmaster we upgrade to Unity 5, and start using it's great new features. You can use Unity 5 from the start if you wish, with only minor code differences.

The course is project-based, so you will not just be learning dry programming concepts, but applying them immediately to real indie games as you go. All the project files will be included, as well as additional references and resources - you'll never get stuck. There are talking-head videos, powerful diagrams, quality screencasts and more.

Oh, and it's just bigger and better than the competition. See the length and the reviews.

For each demo game you build you will follow this process...

  • Be challenged to build the entire game yourself.
  • Be shown step-by step how to build it.
  • Be challenged to apply, and re-apply your knowledge regularly.

You will get full lifetime access for a single one-off fee. The creators are qualified and experienced coders and avid gamers, so are able to explain complex concepts clearly, as well as entertain along the way. Most courses teach scripting using only C#.

You will learn C#, including Test Driven Development, a highly valuable skill. By the end of the course you'll be very confident in the basics of coding and game development, and hungry to learn more.

What this course DOESN'T cover...

Whereas this course is already huge, we can't possibly cover everything in that time. Here are some things we will not be covering...

  • Performance optimization.
  • Editor plugins or modifications.
  • Physics engine modification*

* Separate mini-course to cover these this now available.

Anyone who wants to learn to create games: Unity 3D is a fantastic platform which enables you to make production-quality games. Furthermore these games can be created for Windows, MacOS, iOS (even iOS 9), Android and Web from a single source!

If you're a complete beginner, we'll teach you all the coding and game design principles you'll need. If you're an artist, we'll teach you to bring your assets to life. If you're a coder, we'll teach you game design principles.

Note: access to this course comes with an optional, free community site where you can share games and 3D models, as well as connect with other students.

Dive in now, you won't be disappointed!

What are the requirements?

  • Mac or PC capable of running Unity 3D.
  • A copy of Unity 4.6.3 for early content, free from Unity.
  • A copy of Unity 5 for later content, also free.
  • A copy of Blender, free from www.Blender.org
  • Either some experience of coding, or the will to do self-study.

What am I going to get from this course?

  • Learn C#, a powerful modern language.
  • Develop a positive attitude to problem solving.
  • Gain an excellent general knowledge of game creation.
  • Learn how object oriented programming works in practice.
  • Transfer your knowledge to .NET, other languages, and more.

What is the target audience?

  • Competent and confident with using a computer.
  • Artists who want to learn to bring their assets into games.
  • Some programming experience helpful, but not required.
  • Complete beginners who are willing to work hard.
  • Developers who want to re-skill across to game development.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Introduction And Setup
03:00

In This Video...

  • What’s in the course.
  • Why you should take the course.
  • Good re-cap if a while since signed-up.

03:00

IN THIS VIDEO...

  • We’re excited because we see your improvement.
  • The more you put in, the more you get out.
  • Explaining Unity versions used.
  • Students on 24/7, I’m on every few days.
  • Section notes attached.
03:29

Get Unity downloading, and see an overview of how Unity fits into your suite of programs.

15:26
  • Making it easier for someone to answer means you're more likely to have your problem solved
  • The process will often solve problems before the question is even asked
  • The attitude isn't just appropriate for game development or programming, but for life in general
04:32

IN THIS VIDEO...

  • Checking the version you already have installed.
  • If 4.6.X installed already, you’re good to go.
  • If 5.x installed, install Unity v.4.6.X as well.
  • Finding Unity v.4.6.X in Unity’s download archive*
  • Installing and registering Unity.

* http://unity3d.com/get-unity/download/archive

02:50

Ben outlines the (minor) differences between the Mac and PC version of Unity.

04:05

IN THIS VIDEO...

  • How Unity and Mono relate.
  • Create, delete and rename scripts in Unity.
  • Edit your scripts in Mono.
  • Save your changes to disc in Mono.
  • Unity will then read / run the script for you.
07:50

IN THIS VIDEO...

Let's take our first look at the Unity Editor.

We'll make a few tweaks to help us out in the course, and show you how to navigate in the scene.

After this video you will be able to:

  • Change the play mode tint to make the editor state more explicit
  • Open an existing project
  • Move editor pane around
  • Change the editing mode using the editor buttons
  • Change the editing mode using keyboard shortcuts
04:15

IN THIS VIDEO...

  • We'll take a tour of the MonoDevelop IDE.

After this video you'll be able to:

  • Change the indenting mode
  • Learn and change keyboard shortcuts
  • Use autocomplete to help you program faster

SOME USEFUL LINKS...

Enable Mac Magic Mouse - MagicPrefs

(NOTE YOU CAN CLICK THESE LINKS BELOW)

05:10

IN THIS VIDEO...

  • Save your code, and exit Mono.
  • Practice moving windows again.
  • Toggle 2D & 3D.
  • Rename and save your scene.
  • Save your project when you exit Unity.
  • Move the whole folder if required.
  • Optional: Re-open if you want to carry on.
9 pages

IN THIS VIDEO...

  • Should I install Unity 5?
  • What's new in Unity 5?
  • How do I extend Gamebucket?
  • MonoDevelop doesn't start on Win8.1
2 pages

Here are some useful links for you while using Unity to make games. If you can think of anything to add, don't hesitate to mention it :)

You can view the original document on Google Docs

6 questions

A few basic questions to ensure we communicated the fundamentals of setting-up correctly.

Section 2: Number Wizard: Basic Scripting
01:51

An Introduction to your first Unity Game! Let's get comfortable with coding in Unity. After this section, you'll be able to create and edit your own scripts and print out information on the console.

Section 2 Notes
2 pages
07:31

After watching this video, you will know:

+ How to create a script in Unity

+ How to handle text in your script using strings

+ How to print out messages to the console

04:23

After watching this video you will be able to:

+ Create variables in your script

+ Perform basic maths in your programs

+ Understand what the type of a variable is and why this is important

08:09

After watching this video you will be able to...

+ Respond to a player's key presses.

+ Explain what the `Start()` and `Update()` methods do.

+ Navigate Google and Unity docs with more confidence.

Mid Section QUIZ
8 questions
05:25

After this video you will be able to:

+ Make your programs behave differently depending on conditions using `if` statements

09:20

After watching this video you will be able to...

+ Give a basic explanation of "scope".

+ Use variables in appropriate scope.

+ Use "instance" variables for global access.

+ Use MonoDevelop's autocompletion to help you code faster.

+ **Declare** and **Initialise** variables.

04:05

After watching this video you will be able to:

+ **Refactor** your code in order to make it neater.

+ Create your own custom function.

05:48

In this video we'll clean up our game a little bit and make sure the game restarts properly every time. After watching this video, you will have learnt enough to build your own min console game in code :-)

11:12

Brice covers the following in his video...

  • The Compiler Is Our Friend.
  • The Rubber Duck Sensei.
  • Assume Nothing / Mars Climate Orbiter.
  • The Minimum Viable Test Case.
  • Scientific Debugging.
  • How to debug small programs.
Section End QUIZ
5 questions
02:15

In this video we will review the Number Wizard Console Game and what we learnt while building it. We'll also talk about how we could improve it and a few possible extensions. We'll then take a peek at what's ahead in the next section.

Section 3: Text101 - Text Adventure
02:19

IN THIS VIDEO...

  • What Text 101 teaches
  • Increase our scripting skills (nearly 200 lines!).
  • The basics of “finite state machines”.
  • Invite you to create and share your own story.
  • Build our game to the web.
  • Share with the world.
Section 3 Game Design Document
4 pages
Your Text 101 Assets
1 page
Section 3 Notes
11 pages
07:12

IN THIS VIDEO...

  • Recap how to create and save projects
  • Set Up and save your Text 101 project
  • What gets 'carried over'
  • Import your prison image asset
  • Save your project
15:06

IN THIS VIDEO..

  • Adding a UI > Text element to a scene
  • Setting the camera background colour
  • Moving and scaling your text
  • How to programatically change text
  • Challenge: Change text only on key press
  • Challenge: Add and scale the image
Word Wrapping & Joining Strings
09:07
16:09

IN THIS VIDEO...

  • The structure of our “engine”
  • What's an enum?
  • Challenge: complete the story
Our TextController.cs Script
2 pages
11:28
IN THIS VIDEO...
  • Update Your Update() Method
  • Rename freedom to corridor_0
14:54

IN THIS VIDEO...

  • Add New State Methods.
  • Create your own text adventure.
  • How to enable code folding in Unity.
  • How to use Region to fold code.
  • Local Play Testing.
Our Extended Story Script
4 pages
08:17

IN THIS VIDEO...

  • Encourage you to create your own story.
  • How to build for the web.
  • Test your build locally.
  • Share using GameBucket.io or similar.
  • Post to the course discussions & Facebook.
SOME USEFUL LINKS...
  • GameBucket - Home
  • Complete Unity Developer Facebook page
(NOTE YOU CAN CLICK THESE LINKS BELOW)
05:24
  • Upgrade to Unity 5.
  • About Web GL builds.
  • Build for Web GL and share.
DOWNLOAD Section 3 Unity Project
Article
Section End QUIZ
5 questions
00:57
IN THIS VIDEO...
  • Recap and what's next
  • Did you write your own story?
  • Go on, be brave!
  • Maybe ask a friend to write it?
  • Build for the web.
  • Share in the Udemy Discussions, or www.CompleteUnityDeveloper.com (link below)
Section 4: Number Wizard UI
02:01

In this section, we will go through building a basic User Interface consisting of simple menus. We'll be reusing the code from our previous section to recreate a visual Number Wizard game. After this section, you'll be able to add and modify scripts on objects in your game and create simple menus that respond to mouse input.

3 pages

The Game design Document for the Number Wizard UI Game.

9 pages

These notes are meant as supplementary material for Number Wizard UI.

02:41

In this video, we discuss basic Object Oriented Programming principles and introduce you to the terminology. By the end, you will be able to define the following terms in the context of Object Oriented Programming:

+ Class

+ Instance

Resources

https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)

04:22

After Watching this video, you will be able to

+ Create and Save new Levels

+ Understand that Levels and Scenes are interchangeable terms

13:36

After watching this video, you will be able to:

+ Add a Canvas to a scene

+ Add Text to a Canvas

+ Position Text in a Canvas

05:49

After watching this video you will be able to...

+ Turn a UI Text object into a button by adding the button component

+ Get the text to change colour on mouseover and click

09:01

After watching this video you will be able to:

+ Create a new script

+ Attach Scripts to objects using various methods

+ Trigger function calls from UI buttons

Mid Section QUIZ
5 questions
12:44

After watching this video you will be able to:

+ Use `Application.LoadLevel()` in your scripts to load a new level

+ Use `Application.Quit()` in your games to quit the game

+ Understand when `Application.Quit()` Won't work as expected

10:38

After watching this video you will be able to:

+ Create your own Game Design Document (GDD)

+ Copy and paste scenes hierarchies for fast duplication

+ Understand the purpose and limits of a GDD

18:33

After watching this video you will be able to...

+ Import assets into a Unity project

+ Extract method from your code

+ Connect a script's methods to UI Objects

1 page

The `NumberWizard.cs` file to be imported for reference.

05:36

After watching this video you will be able to...

+ Change the text to reflect the computer's guess at the start of the game.

+ Use `Random.Range()` to generate random numbers

06:29

  • Upgrade to Unity 5.
  • About Web GL builds.
  • Build for Web GL and share.


DOWNLOAD Section 4 Unity Project
Article
Section End QUIZ
5 questions
03:06

In this video, we talk a little more about the structure of the course and how you should approach the challenges. We also show you how you can send us feedback on the course and how to get in touch with us.

Section 5: Block Breaker
02:03
IN THIS VIDEO...
  • 2D Collisions & destroying objects.
  • Triggering SFX and music.
  • Responding to mouse input.
  • Automated playtesting.
  • Build & share your own levels.
Section 5 Game Design Document
3 pages
Your Block Breaker Assets
1 page
Section 5 Notes
34 pages
10:58

IN THIS VIDEO...

  • How to use GIMP as an alternative to PhotoShop (link below)
  • Selecting in Gimp
  • Cropping and Scaling
  • Adjusting Colour and Exposure
  • Saving Your Image
09:20
IN THIS VIDEO...
  • Researching brick sizes.
  • Source an appropriate image.
  • Edit our brick sprites.
  • Create new project and import.
09:36
IN THIS VIDEO...
  • Export the menus from Number Wizard UI.
  • Import to this project.
  • Customise the words & fonts.
  • Wire up the buttons.
09:38

IN THIS VIDEO...

  • How persistent music improves quality.
  • Add a Music Player Game Object.
  • Add a music track of your choice.
  • Use GameObject.DontDestroyOnLoad().
  • Test your music plays consistently.
SOME USEFUL LINKS...
  • Sounds - Freesound.org
(NOTE YOU CAN CLICK THESE LINKS BELOW)
03:32

IN THIS VIDEO...

  • How a static can help us here.
  • Watch Unity's short video*
  • Preventing duplicate music players.

SOME USEFUL LINKS...

  • Unity 3D Statics
(NOTE YOU CAN CLICK THESE LINKS BELOW)
Using Static Variables
07:57
09:45
  • Introducing Script Execution Order*
  • Exactly when do scripts get called?
  • Debugging & explaining our music glitch
  • A simple fix using the Awake() method

SOME USEFUL LINKS...

*http://docs.unity3d.com/Manual/ExecutionOrder.html

(NOTE YOU CAN CLICK THESE LINKS BELOW)

02:50

In this video...

  • What z-depth means.
  • The problem: sprites becoming semi-transparent or invisible for unknown reasons.
  • The solution: look at the z-position of sprites relative to the background.
Setting Up Your Play Space
08:48
08:07
IN THIS VIDEO...
  • Add a ball to your space
  • Import the ball sprite to Sprites folder.
  • Set a sensible “Pixels Per Unit” value.
  • Place the ball in the middle of the play space.
09:41
IN THIS VIDEO...
  • What are colliders
  • If colliders overlap during a frame then…
  • … messages may be passed by the engine.
  • What is message passing?
  • Signatures of messages passed
  • Types of colliders explained
08:35
IN THIS VIDEO...
  • Delete Music Player on Level_01 scene.
  • Setting Game window to 800 x 600.
  • Two handy keyboard shortcuts.
  • Remove Canvas and Event System from Level_01.
  • Make loose collider load next level.
08:25
IN THIS VIDEO...
  • Add our brick sprite as a player paddle.
  • Choosing our paddle collider type.
  • Rigid Body 2D
  • CHALLENGE: Add components to our paddle.
Mid Section QUIZ
7 questions
06:35
IN THIS VIDEO...
  • What is a physics material.
  • Add a bouncy material.
  • Observe funky physics.
13:11

IN THIS VIDEO...

  • Using Input.MousePosition.x
  • Screen.width to get screen width.
  • Move the paddle this.transform.position
  • Introducing float and Vector3.
  • Using Mathf.Clamp to constrain paddle.
  • Fix the paddle's “Pixels per unit” to 128.

SOME USEFUL LINKS...

  • Unity Scripting API

(NOTE YOU CAN CLICK THESE LINKS BELOW)

14:22
IN THIS VIDEO...
  • Start the ball sitting on the paddle.
  • Capture the relative position from the editor.
  • Respond to Input.GetMouseButtonDown(0).
  • rigidbody2D.velocity to launch the ball.
  • Using bool hasStarted to keep track.
10:21
IN THIS VIDEO...
  • Setup all your play space wall colliders.
  • Adjust the initial velocity and gravity.
  • Understanding Gravity Scale
13:05
IN THIS VIDEO...
  • What is a prefab in Unity
  • Why prefabs are useful.
  • Setting up your prefabs.
  • How prefab linking works.
05:42
IN THIS VIDEO...
  • How Edit > Snap Settings works.
  • Snap initially to get on the grid.
  • You can do this with multi-select.
  • Hold cmd (ctrl) while dragging!
  • Build your first level
09:42
IN THIS VIDEO...
  • Make everything a prefab!
  • Set Main Camera background to black.
  • Move & group Loose Collider.
  • Test by making new level.
08:55
IN THIS VIDEO...
  • Why linking prefabs programmatically helps.
  • Unity doesn't support “nested prefabs”.
  • How to use GameObject.FindObjectOfType< >
  • Link the ball to the paddle programatically.
  • Challenge: do this for LevelManager
10:58
IN THIS VIDEO...
  • Create Loose Scene, modify LooseCollider.cs
  • Add LoadNextLevel() to LevelManager.cs
  • Add all our levels to Project > Build Settings
  • Modify Block.cs by adding SimulateWin()
  • Test that game transitions between levels
09:40
IN THIS VIDEO...
  • How the Destroy() method works.*
  • Why we destroy gameObject not this.
  • Challenge: only destroy on max hits
SOME USEFUL LINKS...
  • Object Destroy - Unity scripting API
(NOTE YOU CAN CLICK THESE LINKS BELOW)
15:41
IN THIS VIDEO...
  • Why a sprite sheet is useful.
  • Key features of a sprite sheet.
  • Creating sprites for partially broken blocks.
  • Importing sprites into Unity.
11:57
IN THIS VIDEO...
  • The affordance principle
  • What is an array?
  • Using arrays to store these sprites.
  • Loading sprite when hit.
12:48
IN THIS VIDEO...
  • What are tags?*
  • Why tags are useful for keeping track.
  • Tagging unbreakable bricks.
  • Use tags to decide when level is won.

SOME USEFUL LINKS...

  • Unity 3D Tags

(NOTE YOU CAN CLICK THESE LINKS BELOW)

14:00
IN THIS VIDEO...
  • Why loading levels could be problematic.
  • How a static Brick variable can help.
  • Keeping track of breakable bricks in the level.
  • Creating a simple BrickDestroyed “message”.
  • Testing inc. when 2 bricks destroyed at once.
SOME USEFUL LINKS...
  • Statics to detect win condition end state
(NOTE YOU CAN CLICK THESE LINKS BELOW)
12:03

IN THIS VIDEO...

  • Using audio.Play() to play “boing” sound;
  • Why AudioSource.PlayClipAtPoint useful.
  • Using this for playing “crack”.
  • Test & demonstrate.

SOME USEFUL LINKS...

  • Playing sound effects on impact end state

(NOTE YOU CAN CLICK THESE LINKS BELOW)

Using Random.Range()
08:35

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Ben Tristem, Best-selling Instructor, Game Developer, Online Entrepreneur

Hi, I'm Ben. I have a degree in computing from Imperial College London, and a physics diploma from the Open University.

I started working for myself at the age of 15, and never looked back. I explored careers as varied as being a commercial pilot, stunt-man, rock climbing instructor, and more. None of these provided a continued challenge, and stable income in the same way technology does.

After building and selling a home computer support business, I became an angel investor and business mentor here in Cambridge UK. I fell in love with teaching game development through one of my investments, and I now spend all of my time sharing my passion with people like you.

I can't wait to help you experience the fulfilment, and financial freedom, that having a deep understanding of technology brings.

So why not start learning to make games with me and my team now?

See you soon!

Ben

Instructor Biography

Sam Pattuzzi, Software Engineer, University of Cambridge

I wrote my first game when I was 14 and ever since, programming has been a key part of both work and play in my life. I studied Computer Science at the University of Cambridge where I still teach undergraduates. When I'm not teaching, I'm a freelance software engineer and enjoy my work with tech start-ups and social businesses.

For me, Udemy is the opportunity to combine my passions for teaching and programming.

Ready to start learning?
Take This Course

Beginners Guide To Unity
Getting started in Unity 5

Introduction

Is Unity for Me?

Unity is a video game development environment, popular with professional and amateur game developers. Unity can deploy games to a very wide range of platforms from a single unified base (hence the name). You can deploy your game to mobile, console, PC and much more.

Unity has been gaining respect within the industry for many years. It already has over 80% of the indie developer market, and with the recent improvements in graphics and professional tools, it is becoming a tool of choice for large game houses too.

Whether you're a keen amateur or a game studio looking for a serious development platform, Unity deserves your attention.

This practical guide will get you off to a good start.

Is Unity Just for Making Games?

Actually, no! Unity makes it very easy to develop mobile, desktop and browser applications. Furthermore, you can access geolocation, accelerometers and more. This makes Unity a great tool for any graphics-intensive application, particularly when you want to deploy to multiple platforms.

Companies have used Unity to create product showcases, augmented reality applications, training programs, and much more.

How to Use This Guide

This free guide is designed to help you get into Unity without any programming or game development experience.

If you do have experience, skim through and look for parts that will be useful to you. Note that there is a clickable table of contents at the top of the page, and that you can download our starting point for most exercises.

To get the most from this guide, it is important for you to be active. That is, have a copy of Unity open while you read, and follow along with the exercises. You only truly learn by doing. When you see Cmd / Ctrl + Key I am giving you the PC / Mac alternative, respectively.

If you're wondering when you should be active and when you should just read, look for the numbered lists. A 1, 2, 3 list will be a series of steps designed for you to follow along with. If you leave the guide, remember to save your work so it's ready for you when you come back to it.

Have fun, and feel free to keep a shortcut to this page.

How to Set Up Unity

About Unity Versions

To run Unity, you'll need a reasonably modern Mac or PC; read the system requirements (https://unity3d.com/unity/system-requirements) on Unity's site if in doubt. Let's dive in and get Unity installed. If you've already done this, feel free to jump to the next section.

Using an Older Version

We will be using Unity 5, so if you're running an older version, it would pay to upgrade first. If you don't want to upgrade, Unity 4.6 should be fine too; there will just be some minor differences and extra features in Unity 5.


There are two versions of Unity 5, Personal and Professional. We will be using the Personal edition, which is completely free until you earn $100,000. See "Which Version You Can Use" in Unity's Licence Agreement (http://unity3d.com/legal/eula) for full details. This is an amazing opportunity to use a very powerful system for free.

Downloading and Installing

Installing Unity is as simple as any other piece of software. You will need to register with Unity if you don't already have an account, but don't worry, they respect your email address. There are a few things to consider when installing, however - hence this part of the guide, which you can skim over if you already have Unity installed.

Running Multiple Versions of Unity

If you want to keep a previous version of Unity installed, simply re-name one of your program folders, and leave the other one as Unity. For example, if you want to keep version 4 installed, then rename your program folder from Unity to Unity 4 before running the installer.

Be aware that when Unity updates itself in the future, it will update the version in the folder called Unity.


Follow these steps to get Unity installed:

  1. Download the Unity installer from the Unity download page (https://unity3d.com/get-unity).
  2. Run the installer like you would for any other piece of software.
  3. Leave Unity 5, Web Player and Standard Assets checked as below.





Choosing which components to install on Mac (above), and Windows (below)

  1. If you don't mind Unity overwriting any previous versions, leave the default install location. If you want to install Unity 5 alongside an older version, see the tip below.
  2. The download will take some time, as it's over 1.5 GB in size.
  3. Log in if you already have an account, or create a Unity account at https://accounts.unity3d.com. You'll need to check your email to verify your address.
  4. Well done - the Unity installation is complete.

Running Unity Via Virtual Desktop

Here's a cool tip for you if you're on a device that can't run Unity, but have access to a machine that can. You could run desktop sharing software, (https://en.wikipedia.org/wiki/Desktop_sharing) and access Unity remotely on your netbook, Linux machine, Chromebook, or even iPad.


Creating a New Project

When you first start Unity 5, you will see the project dialog below. Simply click New Project to get started.






The project dialog the first time you run Unity, on Mac and Windows

Once you're inside Unity, you can create a new project from File > New Project, or open an existing one using File > Open Project... pretty standard stuff!

Below is the default interface of Unity. This is where you'll be spending a lot of your time. There is one other program to consider, MonoDevelop, which is an Integrated Development Environment (IDE) for writing your code.






As you can see from the screenshot, the interface is made up of several "Tabs", such as Hierarchy, Scene, Game, Inspector, Project and Console. You'll also notice that Mac and Windows versions are very similar looking, so from now on I'll only include Windows screenshots if the differences are significant.

Even though you may not understand what any of them do, let's get comfortable with the interface now.

  1. Try grabbing the bars between tabs to re-size them.
  2. Try adding new tabs by right-clicking as shown above.
  3. Grab a tab and drag it to detach the window.
  4. Revert to the default layout by clicking Layout at the top right. (see below)



Getting back to Unity's default layout

Dive Into C-Sharp (C#)

We will be teaching you to write games in C#. This is pronounced "C-Sharp" but written C# like the musical notation. C# is a powerful, modern and highly transferable programming language that forms the basis of Microsoft's .NET framework. Better still, this has just been made open-source, making it an even more valuable language to learn.

Languages Unity Supports

It is also possible to code in UnityScript, a variation on JavaScript. However, there are some restrictions to what is possible. This guide will be focusing solely on C#. Unity formerly supported Boo, which has since been discontinued.


Why We're Coding First

Brian Tracy has written a book called Eat That Frog! The idea is that if you have something unpleasant to do, do it first. Unity has a lot of bells and whistles, and the temptation is to dive in and start making pretty things bounce around. While this is extremely satisfying at first, the reality is that you need to know how to code to make a unique game.




Image from Wikipedia, created by Brian Gratwicke.

We'll focus on learning the basics of code before we start playing with the pretty stuff. That way, when we do get to the more advanced tools, you'll understand how to use and modify them properly. Getting this done now will greatly improve your experience with Unity.

Writing Your First Script

Unity comes bundled with an Integrated Development Environment (IDE) called MonoDevelop. This is like a text editor, with some extra features to help you write scripts more quickly and accurately.

Using Visual Studio With Unity

If you're more advanced and prefer a different IDE, it is possible to use Visual Studio with Unity. However, doing so is beyond the scope of this guide.


You must save your file in MonoDevelop in order for Unity to notice the changes. Let's dive in and write our first code.

  1. Find the Project tab (at the lower left by default), and right-click in the Assets pane. Choose Create > C# Script. Name the script HelloWorld. Unity will automatically add a .cs (C-Sharp) on the end.
  2. Drag this new script onto the Main Camera in the Hierarchy. Scripts must be attached to objects to run.
  3. Note that when you "Inspect" the Main Camera, there is now a script attached.



    How to attach a script to a game object

  4. Double-click the script in your Assets, and after a few seconds, MonoDevelop should open. All new scripts start looking like the one below. For now, let's focus only on what we're going to write inside the Start () method on line 8. You'll learn what all this means later.





    How MonoDevelop appears on Mac (above) and PC (below)

  5. It is a programming tradition to start with a "Hello World!" exercise, so let's not break that tradition. Add the following code on line 8, as shown above: print ("Hello World"); exactly as written.
  6. Save your file in MonoDevelop with Ctrl/Cmd+S. This will allow Unity to see the change.
  7. Go back to your Unity window, and hit the Play button (or click Edit > Play). You should see your message in the console tab as shown below.



    How to run your "game", and see the Console output

How to Rename a Script in Unity

If you want to rename your script, do it from within MonoDevelop by highlighting the name after the word class, and using Cmd/Ctrl + R (for Rename). Type the new name, starting with a capital letter, leave the checkbox ticked, and click OK. This will rename the class (more on that later) and the file name for you.




Renaming a script in MonoDevelop

Congratulations - you've written your first line of code. This process of writing scripts and attaching to game objects underpins how you will customise Unity to your needs. With some experience and careful planning, your imagination becomes the only limit to what you can do with Unity.

C# Syntax Basics

It's all fine and good to copy and paste my code. Of course it worked... I had the unfair advantage of trying it before I wrote it. What we really need is for you to learn why the code is written that way.

Again, don't worry about the context for now; let's learn to code "inside out". That means you should understand this line, then Start (), Update (), etc., before eventually understanding the cryptic looking public class HelloWorld : MonoBehaviour {} and other code.




  1. This is a statement; all statements end in a ; in C#. print () is a method, sometimes called a function - it does something.
  2. "Hello World!" is a parameter; it tells the method how to do its job.
  3. The quotes around Hello World indicate that it is a string (of characters).

Note how MonoDevelop has highlighted the string in orange for us. Try removing the first " and you will see that the orange highlight doesn't start until later in the line. Furthermore, the whole line of code is now invalid, because MonoDevelop is expecting a string inside print (); Try this yourself by hitting Cmd/Ctrl + B. This will Build your project, and check your code.




The errors caused by missing a character

You can see from this string of errors that it's pretty important that you write your code precisely. Even a single missing character can cause what seems like a whole load of trouble. Don't worry - once you put the leading " back in, all will be good in the world again. The following notes are especially important:

  1. Capitalisation matters; a change in case can change the meaning a lot.
  2. All statements must end with a ; except in certain circumstances you'll see later.
  3. The indentation of the lines is not required, but is highly recommended.

Now that you know how to follow along, we will do the rest of our learning "in context", by actually making games.

Basic Game Design

In this section you will make your first working game in Unity. I believe the best way to learn is in time and in context. That means we will focus on one clear outcome, then learn what we need exactly when we need it, and in the context of the problem we are trying to solve.

Concept, Rules and Requirements

I'm a great fan of "just doing it", but a certain amount of planning is vital. Imagine you're doing a jigsaw. The minimum planning necessary is making sure the table you're using is big enough... otherwise moving it could be messy. It's the same with your game.

Here are three things to consider when do your initial plan:

Concept What's this game about? Imagine you're telling your mate.
Rules Can you win / lose? How? What other rules are there?
Requirements What assets will we need? 2D / 3D Art? Music? Sound?

By just taking the time to write these things down, possibly with a few sketches, you'll be surprised how much it helps keep you on track later. This is especially important when working with other people, so that you're literally all on the same page!

Start With Simple Games

It's a common mistake to try and think of an original idea for your first few games. It's much better to "learn the ropes" with a known concept. That way, you can hone your development, deployment and marketing skills before unleashing your dream game on the world.


Marble Maze Concept

Concept A simple physics-based "marble maze" game. The idea is to tilt the play space, and get the ball into the goal.
Rules The ball must come to rest in the bottom of the hole to win. If the ball leaves the play space, you lose.
Requirements
  • Two maze 3D models to act as the first two levels.
  • A ball rolling sound.
  • A sound for the ball hitting the walls.
  • A gamepad if you want to try controlling that way.

For tilt control...
  • A USB cable
  • The Unity Remote app
  • An iOS or Android device*

*No Windows Phone at this stage, I'm afraid, as it requires a special Unity plugin.




A rough mock-up of our play space

For the purposes of this guide, we will supply the 3D models required. If you want to learn more about 3D modelling, see The Complete Blender Creator at https://www.udemy.com/blendertutorial.

Lean Game Production

We will be practicing lean game production. This means that we will be trying to minimise waste caused by mistakes by getting a basic version of our game working as soon as possible. We will continually focus on getting our game into a playable state, on a real target device, so that we can get player feedback.

We will organise our workflow so that it is easy to make changes later. That way, we can keep iterating our design until it's just right. We don't really know what's going to work until we see emotion on a player's face, and anything getting in the way of that happening is "fat" in the production process that we need to cut out.

Shipping means getting the product out into the wider world for feedback. It's scary, but it's vital. Seth Godin has done a lot of great work which will help you combat any "resistance" to shipping.

Getting the Ball Rolling

In this section we will create our first "scene". A scene is a collection of assets such as models, sound, etc. Some games use one scene per level; other times, everything can be done in one scene. In our case, we will start off with a single scene.

Create a Game Scene

To get your scene set up, and your board imported, follow these steps:

  1. Create a new 3D project as described above.
  2. Save your first scene immediately as Game by clicking File > Save.
  3. Download the Maze01.fbx model. Import it into your Assets folder as below:



    Right-click in Assets tab to bring up this menu

  4. Drag this model from your Assets to your Hierarchy to create an instance of this model in your Scene.



    How to drag the model into your scene / hierarchy

  5. Congratulations - you have imported your first 3D model in Unity.

About Hierarchy and Scene

The hierarchy is simply a text representation of everything in this scene. So the Game.unity scene contains a Main Camera, Directional Light and Maze01 3D model.


A Ball With Physics

The maze play space is very basic right now, and that's fine. It's what we call a placeholder asset. The biggest thing stopping this game being fun right now is the lack of ball, and the inability to tilt the play space. Add a ball as follows:

  1. Open your project, or download ours.
  2. Click GameObject > 3D Object > Sphere to add a sphere to the scene. Re-name the Sphere to Ball, either by clicking it twice slowly in the Hierarchy, or by renaming at the top of the Inspector and hitting enter.
  3. Move the Ball to (0, 0.6, 0) by setting the Transform values in the inspector. We will make the ball look prettier later.



    Re-naming, and setting the transform position of a game object

  4. Add a Rigidbody to the Sphere by clicking the Add Component button at the bottom of the inspector, and choosing Physics > Rigidbody. This will make the physics engine control the sphere.



    Adding a component to a game object in Unity

  5. Select the Main Camera in the Hierarchy, and Position it at (12, 10, -10). Set the Rotation to (40, -50, 0).
  6. Play the game and notice that the ball falls through the floor. This is because the Maze01 game object does not a have a "collider" required for it to act like a solid object.

    About Play and Play Mode Tint

    When you click the Play button, certain windows in the editor are tinted a different color. Any changes made in these windows are not applied while in Play mode. Be sure to click the Play button again before making changes you wish to save.


  7. Expand the Maze01 game object in the Hierarchy, and find the Maze Mesh child object. Add a Mesh Collider to the Maze Mesh child by clicking Add Component > Physics > Mesh Collider in the Inspector. Depending on how the menu was last set, Mesh Collider may not appear in the list. You may have to type "mesh" in the search box to get to it, or clear the previous search by clicking the little x.



    Selecting the child maze object (the actual mesh), and adding a mesh collider

  8. Run the game again, and note that the sphere now rests on the surface. If the ball still falls through, check it is definitely the child object you added the collider to, not the top-level Maze01 object.
  9. Congratulations - you're making rapid progress.

    Preventing the Player From Getting Stuck

    If you have strong attention to detail, you may have noticed that I put the sphere in the scene 0.1 game units above the ground (it has a radius of 0.5, and we placed it at 0.6). I did this to prevent it getting stuck in the ground.


So, to recap, so far we have added two game objects to Unity. The ball is a primitive object, so we used Unity's built-in sphere. The maze is more complex, and was created in Blender and imported as a .fbx file. This is a common file format for imported assets. Unity does support opening Blender files directly, but you would need the program installed - hence supplying a .fbx.

We then added "colliders" to both objects. These tell Unity's physics engine where the objects are, and prevents them from passing through one another. We also added a rigid body to the ball. This gives the ball mass, and makes gravity act on it. We will be tweaking the physics later.

Preview Tilt Control

Soon we will need to write some script to get some controls (e.g., keys, mobile device's accelerometer, a gamepad, etc.) to move the maze around. However, we can preview the effect of this without doing any coding as follows:

  1. Open your project, or download ours.
  2. Play the game, and select to the Scene tab. The physics engine will now be running, but we can manipulate objects forcefully.
  3. Select the Maze01 object in the Hierarchy, and then chose the rotation tool (or the E key). You can now drag the "ball" in the scene view to rotate the object. Dragging on the colored lines restricts the rotation to one axis.



    Using the rotate tool in Play mode

  4. Note that the ball doesn't currently move. This is because the ball starts resting on the play space, and the moment we rotate the place space the ball gets stuck inside it before it has a chance to move.
  5. Stop the game from running by clicking Play again. This is important because any changes you make while the game is playing will be lost when you stop playing.
  6. Drag the ball inside the Maze01 game object in the Hierarchy. This will make the ball move with the play space. When done right, the ball will be at the same indentations level as the Maze Mesh.



    The Hierarchy before and after "childing"

  7. Play the game again, and rotate the Maze01 object as you did above. Now the ball should roll around the space.

This may be simple stuff, but Unity is doing a lot of work for us here. If you had to write all this from scratch, it would take weeks or months, even for an experienced developer!




Your "game" so far.

Monkey See - Monkey Do?

You may be wondering if you are really learning Unity by following me. I'm a firm believer in challenging you to do things yourself, and in my Unity video course (see https://www.udemy.com/unitycourse) we do this all the time. However, in this written format it's too easy for you to "cheat" by looking ahead, so I'm trying to focus on just telling you what to do and explaining why.


Cross-Platform Controls

You've already had a glimpse of the power of Unity's physics engine. Now we are going to explore another one of Unity's strengths: its ability to deploy a game to many platforms from the same code base.

Without additional licences or modules, you can deploy your game to:

  1. The Web (as an HTML 5 game that doesn't even need a browser plugin).
  2. PC, Mac or Linux (yes, proper, stand-alone native apps).
  3. iOS, Android, and Blackberry mobile devices.
  4. Samsung smart TVs.

... and with additional modules and licences, you can deploy to all the major consoles, and Windows phones too.

One Size Doesn't Fit All

While it's amazing to be able to deploy to this many platforms, most games benefit from being designed for a small number of platforms. Even the biggest game studios can struggle when they try and stretch a game too far, usually because of the fundamental differences in control systems.


Unity's Virtual Control System

In order to make best use of this cross-platform ability, we need to use a "virtual" control layer. This sits between the physical controls and your code, and is one of the things that makes this cross-platform ability possible.




Visualising a virtual control layer

Many of the tutorials and forums on the web will be using a code "class" called Input. to process user input. We will be using CrossPlatformInputManager. It's a bit of a mouthful, and takes a couple more steps, but it will be worth it when you get to switch your game from web, to Mac, to mobile and more effortlessly.

The CrossPlatformInput Package

We're going to import our first standard Unity asset pack. This contains a lot of very useful scripts and "prefabs" (prefabricated game objects) for making our game work on many devices.

  1. Open your project, or download ours.
  2. Click Assets > Import Package > CrossPlatformInput. If you don't have this in your menus, download the asset pack from Unity's website here.


    How to download Unity's standard assets pack if missing

  3. Import the whole asset pack by leaving all the boxes checked, and clicking Import.



    Importing all assets in a pack

  4. Confirm that the pack has imported by looking in your Project tab, and finding CrossPlatformInputManager.cs in Assets > Standard Assets > CrossPlatformInput > Scripts.



    Finding a script in the standard assets pack

  5. Well done - you've learned another useful Unity skill: importing asset packs. Note that the package will have also installed a folder called "Editor". Leave this as is, as the package may need it to function correctly.

    Use the Asset Store

    Another of Unity's huge strengths is its thriving Asset Store. This is an online repository containing thousands of free and paid-for assets, including useful scripts, 3D models, 2D sprites, and much more.




    You can find free assets by simply searching right inside the Project tab.

Write Control Code

It's time to get back to coding. In this sub-section, we will write some simple but powerful code that will allow us to tilt our maze, using the keyboard at first. We will then explore how to make this work with gamepads, and even tilt-sensors on your mobile device.

It's Not Really Moving

A movie is simply a fast sequence of still frames. A game works the same way, giving the illusion of movement by rapidly playing one frame after another. In between these frames, little or nothing happens in the game. It is our job to make sure that the frame rate is at least 24-30 frames per second (FPS) to maintain this illusion.


In the introduction, you saw how to call a method inside Start(), and I explained that this code will be run when the game first starts. This time, we need the code to run "continuously", or more precisely, the game must respond to input every frame. To do that, we'll put our code inside the Update() method. Let's see how:

  1. Open your project, or download ours.
  2. Create a new script TiltControl.cs, and attach it to the Maze01 object. You can do this by right-clicking in Assets and choosing Create > C# Script. Drag it to the Maze01 object in the Hierarchy to attach it.
  3. We need access to the CrossPlatformInput module we just imported, to give our TiltControl.cs script access to this. Double-click the script to open it, and add this line at the top of your script: using UnityStandardAssets.CrossPlatformInput;. The order of the using statements doesn't matter.
  4. Inside the Update() method add the following line to print the value of the "Vertical" control axis to the console:

    print (CrossPlatformInputManager.GetAxis ("Vertical")) ;

  5. The final code of TiltControl.cs is below. Now save your script and attach it to the Maze01 parent game object.



    The tilt control script at this stage

  6. Hit Play to start the game. Click on your Console tab so you can see the print statements.
  7. Finally, click into the Game window, then press the up and down arrow (or W and S) on your keyboard. You will see the values rapidly approach +1 and -1, respectively.



    Input values printed to console (must be in Play mode, and clicked in Game tab)

  8. Well done - you are reading control input.

Let's break that line of code down:

print (CrossPlatformInputManager.GetAxis ("Vertical"));

First, we have a print (); method that we saw before. Inside the brackets, this statement expects something it can print. CrossPlatformInputManager is something called a class. This is collection of related methods, or recipes for doing something. Think of it like a specific cookbook, if you like.

One of the methods of this class is GetAxis (). This method takes in a string to tell it which axis to "get" the value of. In our case, this string is "Vertical" . The GetAxis () method returns a value - in this case, something called a float, short for a floating-point number. This is a decimal number which can take a large range of values, but in our case, -1 represents fully down, and +1 fully up.

Why the Keyboard Value Isn't Just +/- 1

You'll notice the value coming from your key-presses doesn't go to +/- 1 immediately by default. This is something called "gravity", and it helps the keyboard controls respond more like a trackpad or tilt. You can read more about this in Unity's docs here.


When writing your code, MonoDevelop helps you understand methods as you type. For this to work the code above, what you are typing must "compile" - that is, make sense to the computer. If it does, you will get a tip coming up as shown below:




MonoDevelop intellisense

Using a Gamepad

Our game is ready to accept input from a gamepad without any further work. Simply:

  1. Connect your gamepad the way you usually would; Play your game.
  2. Click into the Game window.
  3. Move the left stick up and down. You should see the value in the console change.

Unity Isn't Responding to My Gamepad

The gamepad must be connected when Unity opens. If Unity isn't responding to your gamepad, then close Unity, check that your gamepad is connected, and re-open Unity.


Keep your gamepad handy if you have one. In the next section, we will make our controls actually tilt the playspace, and the fun will really begin.

Cross-Platform Input Code

In this section, we will actually move the play space. There will be a few new programming concepts to introduce, including variables, a new type called Vector3, and how to access an object's "transform" to rotate it.

How to Declare Variables in C#

The general pattern for declaring variables in C#, and giving them an initial value, is:

type varName = initialValue;

The type will usually start with an uppercase letter, except for some common built-in "primitive" types like float, string and int. The convention is to write the variable name with a lowercase first letter, but uppercase midway to emphasise words is fine.

The initialValue must be of the same type as declared on the left. That is, a string must be stored in a string, a float in a float, etc.


Use an Input Variable

As the value of the horizontal and vertical axis input varies from -1 to +1, we need to somehow tell Unity to rotate the maze by a number of degrees proportional to that. For example, we may decide that pushing the control stick all the way up (a value of +1) leads to a rotation of 90 degrees, or 30 degrees. This is our choice of control sensitivity, which you've probably seen in the menu of your games.

Because this value will vary while the game is playing, we need something called a variable. In this case, we need to store two floating-point numbers for the horizontal and vertical input values. C# comes with a handy structure for storing three floating point numbers, called Vector3.

Why three numbers, and why Vector3? Because even though we are not rotating in the y-axis this time, in general we may want to. Also, when we come to rotate the maze in the next sub-section, we will need to supply a Vector3 so we might as well start with one.

  1. Open your project, or download ours, and open the TiltControl.cs script.
  2. Just inside the Update () method, add Vector3 inputValue;. See the screenshot after this exercise if unsure.
  3. Change the next lines inside the Update() method to the following:
  4. inputValue.x = CrossPlatformInputManager.GetAxis ("Vertical");
    inputValue.y = 0f;
    inputValue.z = CrossPlatformInputManager.GetAxis ("Horizontal");


  5. Replace the print line so that we can see what's being stored in our variables:
  6. print (inputValue.x + " , " + inputValue.z);

  7. Save your script, and Play the game and look at the console, or easier still, the very bottom-left of the screen in Unity, which shows the last console output. You should now see the values for both the horizontal and vertical control inputs (keys or keypad).
  8. Well done - you're getting close!


    The current state of our control code

Why Write 0f In C#

The f after the zero tells C# that this is a float. In the case of zero, this can be left out, but it's good practice to write it in for now because if it was any other number than zero, you would get an error if you didn't explicitly tell the computer what type your number is.


It is tempting to try and read the input value, and use it to set the rotation one step. However, if it doesn't work, it can be very hard to work out what's going wrong. It doesn't take much extra time to check that the values are correct in the console before trying to use them like this, and will often save you a lot of head-scratching later!

Rotate Object From Code

Here we're going to find out how to manipulate a game object's transform from code.

  1. Open your project, or download ours, and go back into your TiltControl.cs script.
  2. At the bottom of the Update method, add the line below. It must come at the bottom because we can't use the variable until after we've declared it:

    transform.eulerAngles = inputValue;

  3. Play the game, click into the Game window, and try using the cursor keys (or WSAD). If you have a gamepad, try that too. Note that the play space tilts, but only a tiny bit - in fact, it's only tilting 1 degree.
  4. Well done - you have working cross-platform controls. Now we need to implement control sensitivity.

Here's the line of code we added:

transform.eulerAngles = inputValue;

The transform.eulerAngles on the left-hand side corresponds to the transform component of the game object that the current script is on. Because TiltControl.cs is on the Maze01 gameobject, transform corresponds to that rotation of Maze01.

The .eulerAngles bit is the way of accessing the rotation property of the transform. This is equivalent to setting the rotation in degrees in the inspector, but of course your player can't do this when the game is running, so this is how to do it in code.




Accessing the rotation from script

Local vs. Global Coordinates

When you explore Unity on your own, you will come across local vs. global coordinates. In this simple game, with the maze at the origin with no rotation, there is no difference between the two for all practical purposes. However, be aware that there is a difference. There is a reasonable explanation here, among other places.


Create a Sensitivity Control

A one-degree tilt does not necessarily make for an exciting game. So, here's how to use another variable to allow you to tweak the control sensitivity. In a more advanced version of this game, you could even create a User Interface (UI) to allow your player to change this for themselves. It is our job to find a workable starting point, however.

  1. Open your project, or download ours. Go back into your TiltControl.cs script once more.
  2. We need a variable that is accessible in the inspector. To do this, add the following line of code under the "class definition":

    public float sensitivity = 90f;

    Remember to indent your code using the Tab key. When you have finished, it should look like this:




    Where to add a public variable

  3. Now edit the line that does the rotation to multiply the input values by the sensitivity:

    transform.eulerAngles = inputValue * sensitivity;


    In this case, we will now be rotating +/- 90 degrees because as the components of the input value vary from -1 to +1, they will be multiplied by 90.

  4. Save your script, and Play the game again, and note that the rotation is now a full 90 degrees. Using values you can visually verify like this at first makes sense.
  5. Stop the game, and click on Maze01 in the inspector. Note that you can now change the sensitivity in the inspector now. Set the value to 30, to make the maximum tilt 30 degrees.



    Setting a public variable in the inspector

  6. Play once again, and notice that the maximum tilt is lower. Experiment with changing this value in Play mode, and when the game is stopped. Note that the value is not kept if changed in Play mode.
  7. Finally, note that the camera is in an awkward place to play the game. We'll fix that later, but for now, let's pretend we missed it and carried on to ship our game.

Public Values in Code and Inspector

Note that we gave our sensitivity control a value in the code (90 degrees), and another one in the inspector (30 degrees). You may wonder which one takes precedence, and isn't it dangerous to have a value in two places.

The value in the inspector overrides that in the code. However, it's still a good idea to set a sensible starting value in the code.


Polish and Deploy

Our game is far from perfect at this stage, but it is playable. Let's fix the obvious issues, then share to get our very first feedback. The reason is to spot things that we're too close to notice, and fix them super early.

Fix Obvious Issues

Before I'm willing to share this with anyone, I would want to at least sort out the following glaring issues. Be careful, though, as it's tempting to never "ship" your game because of perfectionism. Get the basics working, and share your game.

Here are the three, and only three, issues we're going to fix for now.

  1. The ball moves too slowly. Why? Because the physics engine is set up to simulate 1 world unit = 1 meter by default. That means we have a 1m diameter ball, on a 16m play space. That's like a huge beach ball on a tennis court - no wonder it's slow! We'll fix it by increasing gravity at least 10 times.
  2. The controls don't "line up" with the screen. This is because we haven't tried to make them line up yet. The maze has an arbitrary rotation, and we need to make some changes to get the controls lined up. However, at the same time, we must take care of the next problem.
  3. The viewing angle is awkward. In our haste to get to a working game, we didn't really think about the camera angle. That's a good thing, because you don't really know how you want it until you can play it. Now that we can play it, it's time to fix the camera angle and the control alignment at the same time.

Let's fix all three of these issues at once.

  1. Open your project, or download ours.
  2. Move the Main Camera to (0, 10, 8) with a rotation of (50, 180, 0). This helps with the view, but now the vertical controls are reversed.
  3. Open TiltControl.cs and modify the line below by adding a minus sign after the = sign. This will reverse the vertical control values. Remember to save your script.

    inputValue.x = - CrossPlatformInputManager.GetAxis ("Vertical");


  4. Make sure your game is NOT in Play mode, and click Edit > Project Settings > Physics. Set the Gravity Y scale to -100, about 10 times bigger than it was but still pointing down. This will accelerate the ball faster.



    Increasing the gravity scale of your game

  5. Play the game again, and note that it's all much nicer now.

Convert Project to Web

In this sub-section, we will show you how to use Unity's "Build Settings" to change the target platform of your game to WebGL. This feature is new to Unity 5, and allows you to make games that run in a browser using HTML 5, without the player even needing a plugin.

Here's how to convert your Unity project to a web build.

  1. Open your project, or download ours.
  2. Click File > Build Settings to bring up the platform build settings.
  3. Add the Game scene by either clicking Add Current, or dragging it from the Project tab into the "Scenes In Build" panel.
  4. Under Platform chose WebGL, and click Switch Platform.



    Build settings for deploying to the web

  5. Now click Build And Run and chose where to save your web build. Call it web; this will become the folder name. The build will take a while. When it has finished, your default browser should launch, and some time later, the game should start playing in the browser.

You now should have a fully functioning game in the web. There are a couple of limitations: the gamepad controls won't work. For that, you'll need to build again for PC, Mac or Linux. Also, you'll need to use Chrome, Firefox or Safari as a browser.

You can also build to "Web Player". This will work in Internet Explorer, and the gamepad input will work. However, your player will need the Unity plugin installed.

Sharing Your Web Game

If you want to share your game, you could zip and send the marble folder to a friend for him or her to play locally. Alternatively, you could "host" this file on some web hosting if you know how to do that.

If you have a paid version of Dropbox, you can simply put it in your Public folder and share the public link. There will be a limit to how much bandwidth you can use this way. You can play my version on Dropbox here.

Next Steps

Thank you for reading this guide. If you have just skimmed through it, then I encourage you to take some time to go back and follow the exercises through. Remember, you don't need to do all of them, as I provide a starting state for every exercise for you to download.

Please continue your Unity education by searching for YouTube videos, and consider enrolling in our epic 50-hour Udemy video course at https://www.udemy.com/unitycourse.

If you prefer the written format, you can pre-order my upcoming book from Amazon via http://bit.ly/bensunitybook.

It's been a pleasure teaching you.

Ben Tristem

This guide was written by Ben Tristem for Udemy.