Unity is a game engine (a software development environment where people create video games).
The video games can be run on the web (and lots of other places).
There's lots more information at Wikipedia and Unity.
There is a free version of Unity (some restrictions apply).
Everything in my lessons can be done with the FREE version.
Go to unity.com to get the latest version.
Download the Unity Hub (which manages all your Unity projects and installations);
the Hub guides you through the rest of the installation.
In particular, you'll need to add a Unity version.
[Data from my install:
January 5, 2020
UnityHubSetup, 58.5 Mb, very quick;
add latest Unity version with Windows-related modules, 2019.2.17f1, download/install took 44 minutes]
My experience getting/using Unity: sometimes it looks like nothing is happening.
Be patient! Look around for a progress bar (which may not be obvious/identifiable until some progress is made).
To uninstall Unity (if you decide not to use it):
Unity HubInstallsuninstall desired version(s)
Then, use your computer's ‘add or remove programs’ method to uninstall the Unity Hub.
Unity User Manual
The searchable Unity User Manual is here.
(You may need to switch to a different version.)
Consider bookmarking the user manual for easier future access.
Read it start-to-finish, or use it as a reference.
Open the Unity Hub
You should have a shortcut to the Unity Hub on your desktop; double-click it.
(I delete the desktop shortcut to the specific Unity version: it gets you to the same place, but takes longer.)
desktop shortcut to Unity Hub
Create a New Project
In the Unity Hub, click NEW to create a new project.
What template to use?
Select the 2D (two-dimensional) template.
(Be careful! It's probably not the default template.)
What is the project name?
Give your project an appropriate name. (My name: ‘Expressions versus Sentences’)
The name you choose automatically becomes the name of the Main Project Folder
(where the project is stored on your computer).
Where should Main Project Folders be stored on your computer?
You may want to create your own ‘Unity Projects’ folder in a desired location on your computer.
Click Create. It may take a few minutes.
When finished, your new project
will open in the Unity Editor (discussed below).
Note: In these lessons, I use the words ‘project’ and ‘game’ interchangeably.
Note: I may say just ‘Hub’ instead of ‘Unity Hub’.
This shows the ‘Expressions versus Sentences’ project in the Unity Hub.
Click the three vertical dots to the far right of the project
to see some menu items.
FYI: Look at the Main Project Folder on your Computer
When you create a new project in Unity, a Main Project Folder is created on your computer.
The image at right shows the contents of the ‘Expressions versus Sentences’ Main Project Folder that was just created.
How to Delete a Unity Project
If you ever want to delete the ‘Expressions versus Sentences’ project, do the following:
In the Unity Hub, click the vertical dots to the far right of the project.
Choose Remove From List.
The project will no longer appear in the Hub list, but this does not get rid of the project files on your computer.
To get rid of the project files on your computer:
delete the ‘Expressions versus Sentences’ Main Project Folder on your computer.
Note: The image at right shows the contents of the Main Project Folder.
If you want to delete the Main Project Folder, you need to go up one level in the directory structure.
contents of the Main Project Folder
for the ‘Expressions versus Sentences’ project
Once a project is created, it is available from the Unity Hub. See (1) at right.
Click on the project to open the Unity Editor.
Important Unity Editor Elements
See (2) at right.
The Toolbar has the following groups:
Left: tools for manipulating scenes/objects; hover over an icon to get a tool tip
Center: play/pause/step controls (for ‘playing’ your game)
Right: access to Unity services/account; layers/layout tools
Above the Toolbar (but not shown at right) is the Main Menu (File, Edit, ...).
Scene View and Game View
Notice the separate tabs for Scene and Game.
In both Scene and Game views, the scroll wheel can be used to zoom.
Scene View is your interactive view into the world you are creating.
In Scene View, you arrange scenery/characters/cameras/lights etc.
Game View represents your final, published game. Game View is rendered from the camera(s) in your game.
Therefore, you must have one or more cameras, since they control
what the player actually sees.
Keyboard Shortcuts for Scene View and Game View:
Scene View: cntl-1
Game View: cntl-2
Hierarchy Window Scenes contain the environments/menus of your game.
Think of each unique scene file as a unique level.
A sample scene may be loaded to get you started.
The Hierarchy Window represents every object in a scene.
The Hierarchy Window reveals the structure of how objects are related to one another.
Note: An asterisk (*) appears next to objects with unsaved changes.
The Inspector Window allows you to view/edit all the properties of a currently-selected object.
An asset is any item for use in a project (for example: images, audio files, textures, ...)
All assets are shown in the Project Window.
Some assets may come with the template you loaded.
You can also import assets.
Customizing the Unity Editor
Most everything in the Unity Editor can be moved/resized to make the interface your own:
drag tabs to move them
drag boundaries to re-size
(The Toolbar can't be customized.) Toolbar-Layout-Default restores the default layout.
(1) to open a project, click on it in the Unity Hub
(2) important Unity Editor elements in their default layout:
Scene View and Game View
Recovering from Unexpected/Undesirable Behavior
When you first learn a tool, you probably experiment a lot.
If you find yourself saying ‘Eeeekk! What just happened?’ then try the following (in this order):
Undo:cntl-z or Main Menu-Edit-Undo Redo:cntl-y or Main Menu-Edit-Redo
Exit the Unity Editor
Completely exit the editor (Main Menu-File-Exit) and then start again.
As long as you didn't ‘save’ after finding yourself in an undesirable situation,
this may fix the problem.
Git: a free version-control system for tracking changes in source code during development
Not everything can be ‘undone’ by cntl-z or exiting the Unity editor.
Some actions (albeit unintentional) persisteven after a complete exit and re-open.
This is one reason why many people use git as an important part of their project management.
Git keeps track of all changes made over time, and gives you the ability to recover from anything (even after saving).
My genius husband Ray
created an easy way to set up a git repository for a Unity project.
(A git repository is a file location that stores all project-related files.
When you ‘git commit’ a project, a version/snapshot is created in this repository.)
Click the button below to find out how to do it.
Even though you may choose to ignore this on a first reading,
definitely come back and set it up at a near-future time!
The process is illustrated by creating a git repository for the ‘Expressions versus Sentences’ Main Project Folder,
located (for me) at:
C:\Users\Carol\Documents\Unity_Projects\Expressions versus Sentences
As these lessons continue, I'll show how to use your repository to
‘go back in time’ to a before-undesirable-behavior project state.
(1) Get the necessary files
Download this zip folder:
When prompted, click ‘Open’.
You will see the two files shown in (1a) at right.
Drag these files into your Main Project Folder (see (1b) at right).
(1a) The zip folder contains these two files.
(1b) Drag the files from (1a) into your Main Project Folder.
Note: For me, ‘This PC’ is an abbreviation for: C:\Users\Carol
These two files are now alongside your other project folders: Asset, Library, Logs, Packages, etc.
(2) Run the ‘.cmd’ file
This file creates the git repository.
There's more info on the Git-Init-For-Unity.cmd file in (5), if you're interested.
Windows is very careful about files that contain commands
(files with a ‘.cmd’ extension), and gives you a warning. To run the file,
you have to tell Windows that it's okay:
(2a) Click ‘More info’.
(2b) Then, click ‘Run anyway’.
(2a) Windows gives you a warning.
Click ‘More info’ to continue.
(2b) Click ‘Run anyway’.
(2c) After the Git-Init-For-Unity.cmd file runs, you will see this screen.
Press (say) the space bar to continue.
Delete the Git-Init-For-Unity.cmd file (as instructed).
Do not delete the .gitignore file!
(2c) This is what you see after the Git-Init-For-Unity.cmd file runs.
(3) Add the repository to Visual Studio
Open Visual Studio (it came with Unity, if you didn't already have it).
Visual Studio is an IDE (Integrated Development Environment) from Microsoft.
Visual Studio will be used for all your code-writing in Unity (more on this later).
Team Explorer-Manage Connections-Add
(If you can't find Team Explorer, use View-Team Explorer.)
(3b) Paste in the location of your Main Project Folder.
(3c) Click Add.
Your new repository will appear.
Double-click on the new repository to make it active.
(3a) In Visual Studio,
Team Explorer-Manage Connections-Add
(3b) Paste in the location
of your Main Project Folder.
(3c) Click Add.
Double-click on the new repository to make it active.
(4) Initialize the repository
(4a) Click Changes.
(4b) Since this is a brand-new repository, everything in your project is a ‘change’!
So, there may be a lot of files.
(4c) Type a message in the indicated box.
Click Commit All.
It may take some time to ‘check everything in’.
Congratulations on setting up your project repository!
(4a) Click Changes.
(4b) Here are all the files in your project.
(4c) Make your first commit!
(5) Info on the Git-Init-For-Unity.cmd file
The Git-Init-For-Unity.cmd file is a text file that is saved with the extension ‘.cmd’.
If you double-click this file, it will execute (that is, run the commands that it contains).
If, instead, you just want to view it (to see what is shown at right), then open it in any software you typically use with ‘.txt’ files (like Notepad in Windows).
This type of file is called a batch file.
There are only three lines where the real work is being done!
Everything else is just for a good user experience.
The two consecutive colons ‘::’ denote single-line comments.
A single colon is used for a label (for changing the top-to-bottom flow of the program).
For example, the line
if not exist .gitignore goto errora
can be ‘translated’ into English as:
If the file .gitignore doesn't exist,
then jump to the line that's marked :errora
The ‘echo .’ just gives an almost-blank line (a line containing a single period),
for easier readability when the file is run.
(It's hard to get a completely blank line in this simple language!)
Even if you have absolutely no coding experience, you can probably read through this program and figure out what it does!
Give it a try!
(5) the contents of the Git-Init-For-Unity.cmd file
Unity Asset Store
The Unity Asset Store offers free and to-purchase assets created by
Unity Technologies and Unity community members.
The Asset Store is available from the Unity Editor:
the ‘Asset Store’ tab in the Scene section
Main Menu-Window-Asset Store
If you want more space to browse the store, click Open In Browser (which should
appear after you click the Asset Store tab).
You need a Unity ID for the Asset Store.
Your Unity ID also allows you to buy/subscribe to Unity products/services and participate in the Unity community.
Make the game your own!
Next, you'll get a background and character for your game at the Asset Store.
By choosing your own (instead of taking my choices), you can make this game your own!
Get a Background for your Game at the Asset Store
I did it this way:
refine search: Category-2D; Pricing-Free Assets
search for ‘desert’
I chose: Free Parallax Desert Background
When you import an asset, you're given the opportunity to preview the files and choose what you want.
(I usually take everything.)
Be sure to click import after your selections.
Large assets may take several minutes to import.
See (1a) at right.
How to Delete an Unwanted Asset from your Project
To delete an asset from your project:
select its top-level folder in Project-Assets (see (1b))
press the keyboard delete key
This action does not remove the asset source file(s) from your computer!
It only removes the asset from the current project.
See (2) at right.
Usually, you'll want to keep assets on your computer, since
they may be useful in other projects.
However, if (say) you need to recover disk space, see (3) at right to remove the original asset files from your computer.
How to Inspect Assets
Use the Project Window to explore your assets.
See (4) at right.
Choose a character that comes with some animations (see (5) at right).
Shortly, you'll see how you can preview these animations.
Other Ways to Get Assets Into Your Game
Drag files directly from File Explorer into the Project Window.
Note: The tooltip changes to a ‘+ inside a square’ when you're in an appropriate place to drop the file(s).
Project Window-right click-Import New Asset...
Unity Automatically Saves New Assets Upon Creation
At the completion of this step,
you will have folders in Project-Assets corresponding to:
a Scenes folder
Unity automatically saves new assets upon creation.
However, subsequent changes to these assets may require a manual save.
Saving All Changes
To save everything after you've made desirable changes,
use Main Menu-File-Save (or keyboard shortcut, cntl-s).
(1a) After importing Free Parallax Desert Background into your project,
a new folder appears in Project-Assets.
(1b) If you subsequently decide to remove this asset from the project,
just delete its top-level folder in Project-Assets (highlighted above).
(2) After importing an asset into your project,
you'll have new folders/files in the Assets subfolder of your Main Project Folder (on your computer).
If you subsequently delete the asset in Project-Assets in the Unity Editor,
then these folders will disappear from your computer.
However, the original asset files are still on your computer (for potential use in other projects).
(3) The original asset files are hidden deep in your computer!
Note: The AppData folder was hidden; I had to ‘show hidden files’ to reveal it.
To completely remove an asset from your computer, delete it here.
(4) A peek inside the Free Parallax Desert Background folder:
when you click on a file (like 1Layer1),
details appear in the Inspector window (at right).
Note: The checkered texture indicates transparency
(objects behind will show through).
(5) my character comes with some animations
The GameObject is the most important concept in the Unity Editor.
Unity says ‘GameObject’ (no space), rather than ‘Game Object’.
Every object in your game is a GameObject: characters, props, scenery, cameras, special effects, and so on.
A GameObject can’t do anything on its own.
A GameObject is a container for Components, which implement all appearance and functionality.
(Unity tends to capitalize ‘Components’.)
Think of a GameObject as an empty cooking pot.
The GameObject's Components are the ingredients that make it look/behave in desired ways.
A GameObject can have childrenmore on this later.
This game has only one scene.
For me, the default name is SampleScene. See (1a) and (1b) at right.
Cameras Cameras capture and display your ‘game world’ to the player.
The 2D template comes with an orthographic camera called Main Camera. Orthographic means that the camera renders objects uniformly, with no sense of perspective (which is appropriate for a 2D game). Main Camera is a GameObject configured in an appropriate way.
Delete all GameObjects Except Main Camera
If you have any GameObject other than Main Camera in SampleScene, delete it now.
To delete a GameObject, select it in Hierarchy and press the delete key.
Save your Changes
Get in the habit of saving your changes after you've done something desirable!
Argh! What if you lose your Main Camera?
If something happens and you lose Main Camera, don't despair!
Here's how to get one that matches what came with the 2D template.
(Don't worry about what all these mean right now!)
Create a new Camera GameObject Main Menu-GameObject-Camera
Select Camera in Hierarchy.
Click Cameraagain to rename.
Type in ‘Main Camera’.
In Inspector, change:
Tag to MainCamera
Transform-Position-Z to $\,-10\,$
Camera-Clear Flags to Solid Color
Camera-Projection to Orthographic
Camera-Depth to $\,-1\,$
un-check Inspector-Camera-Occlusion Culling
change Inspector-Camera-MSAA to Off
There will still be one minor difference, which might only affect things if you're working with virtual reality.
The 2D-template Main Camera has a Target Eye property with value None (Main Display).
However, when you create a new Camera GameObject, there is noTarget Eye property at all!
By digging deep into code, my genius husband Ray discovered the following:
Target Eye set to none (Main Display)
corresponds to an internal value of 0; Target Eye set to Both
corresponds to an internal value of 3.
A newly-created Camera GameObject has Target Eye set to Both.
When Target Eye is Both
and Virtual Reality is not supported, the Target Eye property vanishes, due to this line in the Unity code: