© Casey Hardman  2020
C. HardmanGame Programming with Unity and C#https://doi.org/10.1007/978-1-4842-5656-5_1

1. Installation and Setup

Casey Hardman1 
(1)
West Palm Beach, FL, USA
 

Installing software is somewhat simple – download an installer, run the installer, a menu (sometimes called a “wizard”) pops up, you agree to some terms of use, it asks you where you want to install the program on your computer, maybe it offers some additional options, and then it starts installing. Easy, right? So I won’t go into painstaking detail over the installation process. I’ll just show you what to install.

Installing Unity

Unity is frequently releasing new versions with new features, bug fixes, and little improvements. Because of this, they’ve recently come up with what they call Unity Hub. It’s a lightweight little application that lets you install the actual Unity engine, including older versions of the engine. It also lets you manage older versions of the engine already installed on your computer and view all your Unity projects from one place.

Sometimes it’s useful to keep an old version of Unity around even after you upgrade to the latest version. You may want to work on an older project with the same version you started with, in case some new features or changes aren’t compatible with your old project – things change, and sometimes the new stuff breaks the old stuff. Sometimes the old stuff just gets reworked and isn’t valid in a newer engine. In those cases, you might decide to stick to the old version until you finish a project, to avoid spending unnecessary time changing the way you did something to the “new way.”

So we’re going to install the Unity Hub first, and then we can install the Unity engine itself through the Hub. To download the Hub, navigate to this link in your web browser:

https://unity3d.com/get-unity/download

Click the button titled “Download Unity Hub,” as shown in Figure 1-1.
../images/486227_1_En_1_Chapter/486227_1_En_1_Fig1_HTML.jpg
Figure 1-1

Download Unity Hub button

The Hub installer will begin to download. Run the installer and follow the prompts.

Once the Hub is installed, run it. You may be prevented from getting very far by Unity asking you to accept a license, which may involve creating an account with Unity. This is a little one-time setup that pretty much stays logged in and accounted for afterward. It won’t bother you much once it’s done – but still, if you’re prompted to make an account, don’t forget your password and username!

To understand what the “license” is, know that Unity used to have a free version and a Pro version. They restricted some of the features from the free version, and you would have to pay for the Pro version if you wanted to use these features – the fancy stuff, particularly fancy 3D lighting and effects. Then, they simply opened up nearly all the features to the free version, while the paid versions offered mostly miscellaneous things like heightened support, extra resources, and team collaboration tools. Now, they offer three different “licenses” to use with the engine: Personal, Plus, and Pro.

As long as you or the company you represent made less than $100,000 in gross revenue in the previous year (that’s us), then you can use Unity’s Personal license, which is free of charge. If your game development career takes off and you start pulling in some money, you’ll eventually have to upgrade to Unity Plus ($25/month) or Unity Pro ($125/month) to avoid violating the license. But let’s not get ahead of ourselves – we’re just hobbyists for now, anyway.

You might also be asked to fill out a little survey. It’s just some questions pertaining to how you plan on using the engine, where your interests lie, and other “get-to-know-you” stuff like that.

Once you’ve got a license and an account, you should see an “Installs” tab on the left side of the Hub (see Figure 1-2).
../images/486227_1_En_1_Chapter/486227_1_En_1_Fig2_HTML.jpg
Figure 1-2

Top-left corner of the Unity Hub, with the Installs tab selected

This is where you can see all the versions of the Unity engine you have installed on your computer. You can also install new versions – although installing many versions can quickly use up space on your hard drive, so you may want to uninstall old versions to avoid this. With the “Installs” tab selected, click the “Add” button in the top-right corner. A popup will offer a list of versions you can choose from. The topmost version will be the latest stable release. Click it to select it; then click Next in the bottom-right corner.

You’ll be asked to select what the Unity Hub calls “modules” to install with the engine. These are extra little features to add to the installation, which take up some extra space on your computer if you choose to install them. You can always add modules later, after installation completes, if you find that you want them. Most notable are the Build Support modules, which allow you to build a Unity game project to different operating systems, environments, and hardware.

“Building” a game project is the process of turning it from a Unity project, playable only through the Unity engine, to an actual application used to play the game.

The major platforms that Unity projects can be built to are
  • PC, with support for Windows, Mac, and Linux

  • Android

  • Apple iOS

  • WebGL (played in a web browser)

  • Xbox One

  • PS4

As I said, if you need to build to these platforms down the road (we won’t get into them in this book), then you can always install them through the Hub.

You can also select to install the Unity documentation locally as a module. The documentation can be immensely helpful. It’s available online as well, and I myself tend to use the online resources, but if you plan on using Unity offline, you may want to install the documentation so it’s available without an Internet connection.

For now, you can simply check the Build Support for the operating system you’re using, and if you want for the documentation, and uncheck everything else. Then click Done, and the installation will begin. The version you’re installing will appear as a box in the main body of the window, and a little bar above it will depict how far along the installation is.

Once it’s done installing, the bar will disappear, and you can now create a Unity project with that version of the engine – in a little bit, we’ll do that and run the engine for the first time. Another nice feature about the Hub is that it will automatically run the correct editor version of Unity when you open a project (assuming the version is still installed on your computer).

Installing Our Code Editor

You don’t write code in the same sort of software that you might write a book or a resume in. Code editors are text editors that are fine-tuned for writing code. They have special highlighting for words and symbols, they know how to format code, and they often come with a slew of features that make it easier and faster for us to write and work with code.

Our code editor of choice is Microsoft Visual Studio Code. It’s not to be mixed up with Microsoft Visual Studio. Both are similar (and similarly named) products from the same company, both are free to use, and you could use either one to do the job. They can both edit C# code and integrate with Unity.

Visual Studio Code is designed to be cross-platform and lightweight out of the box, but highly extensible. It has a minimalistic user interface, and most of its features are enabled through installing extensions to add extra functionality, which you do through the software itself.

Visual Studio has support for Windows and macOS, but not Linux. It comes with more features out of the box. It’s a very powerful tool and certainly has plenty of uses, including collaboration with teams and other such more advanced features. It is generally “heavier” – more feature-rich but likely to consume more memory and run a little slower.

Code is our choice because I feel it’s more suitable for beginners, as it doesn’t “get in the way” as much, and most of the advanced features of Visual Studio don’t really suit our workflow anyway.

To download Code, head on over to this link in your favorite web browser:

https://code.visualstudio.com/download

From there, you can select the correct button to download the software based on your operating system (Windows, Linux, or Mac). The installer should begin to download. Once it completes, run it and follow the instructions it provides.

Once you have Visual Studio Code running for the first time, you’ll see a welcome page serving as a hub for various links and resources. Many programmers are picky about the color scheme their code editor uses. I prefer dark schemes myself. Some prefer light – whatever floats your boat. You can easily change it right from the welcome page. Click the “Color theme” button to pop up a list of standard color themes, allowing you to switch to whichever theme you prefer (see Figure 1-3).
../images/486227_1_En_1_Chapter/486227_1_En_1_Fig3_HTML.jpg
Figure 1-3

Welcome page Color theme button (left) and resulting popup (right)

Once you’re satisfied with your colors (you can always change them again later), let’s close the welcome page. Any file or page you have open in Code will have a tab at the top left (see Figure 1-4) whether it’s an editable code file you’re working on or a static page like the welcome page. If you have multiple files open, you can easily switch to view a different one by clicking the tab. Right now, we only have the welcome page open. Let’s close it to get a blank slate. You can do this by left-clicking the X button on the tab or by using the Ctrl+W hotkey.
../images/486227_1_En_1_Chapter/486227_1_En_1_Fig4_HTML.jpg
Figure 1-4

The top-left corner of Code, where all page tabs are shown. The welcome page tab is the only one we have open here

Once it’s closed, there won’t be much going on – just a big blank space, as shown in Figure 1-5.
../images/486227_1_En_1_Chapter/486227_1_En_1_Fig5_HTML.jpg
Figure 1-5

View of Visual Studio Code with no files open

You can now install what Code calls “extensions” to add some extra functionality to the editor. Extensions are managed and installed through a button on the left sidebar. The left sidebar has a handful of different forms it can take, all based on which of those buttons you pressed last. Mouse over the buttons to see what they mean and click the Extensions button when you find it (it’s the bottom one). You can also press Ctrl+Shift+X to bring it up. This will cause the sidebar to pop up on the left side of the screen. Pressing the button again will fold the sidebar, tucking it away.

Inside the Extensions sidebar, you can search for extensions with the search bar at the top. Click within the search bar and type “C#”. You should see a result simply titled “C#”, with a description “C# for Visual Studio Code.” You’ll also notice that the publisher for the extension is listed beneath the description: “Microsoft,” which so happens to be the company behind Visual Studio Code and C# itself.

Click this extension, and a new tab will pop up, providing details about the extension. Under the main description at the top of the page, you’ll see a button to install the extension. Click that, and the extension will begin installing. If you’re prompted to install any further extensions by popup boxes during this, go ahead and permit them to install.

Next, we’ll install the extension for debugging in Unity. This allows us to “attach” our code editor to Unity, so that we can use the code editor to set up “breakpoints” in the code. A breakpoint is a point in the code that, when reached during the execution of the program, causes the whole program to freeze. While frozen, we can look at pretty much any piece of data from our program that we want and resume whenever we please, among other things. It’s a very handy feature that we’ll use later down the road.

The exact name of the extension is “Debugger for Unity,” published by Unity Technologies. You can find it the same way – by typing the name in the search bar at the top of the Extensions sidebar.

Once you have these extensions installed, we can close Visual Studio Code. We’ll be using it more in Part 2. For now, we’re focused on the Unity editor itself.

Creating a Project

We can now use the Unity Hub to create our first project, so we have an environment to play around in as we learn. In the Unity Hub, click the Projects tab on the left side, and then click the blue “New” button in the top-right corner.

A dialog box will appear (see Figure 1-6), allowing you to select a template to base the project on.
../images/486227_1_En_1_Chapter/486227_1_En_1_Fig6_HTML.jpg
Figure 1-6

Dialog box for creating a new Unity project

The template is just a simple starting point for your project. The most bare-bones and simple templates are the first two, titled “2D” and “3D.” These are pretty much blank slates, one set up for 2D and one for 3D.

We’ll start with a blank 3D project, so select the 3D template by clicking it. It will have a blue border around it if it is selected.

To the right side of the template options, there’s a field for the project name (you can change this later) and the directory (file path) on your computer to save the project files to. We’ll name our project “ExampleProject” – note that we aren’t using a space between the two words, because file paths aren’t always fond of them.

You can change the directory to save the project wherever you like. Whatever file path you choose, a folder named after the project will be created inside that folder. That folder is the “root directory” for your project, and all your project’s files and resources will be stored in that folder.

Once you’ve selected the path you want, click the blue “Create” button in the bottom-right corner, and wait for Unity to create the base project files. When Unity finishes, the editor itself will pop up with your brand-new project opened and ready for editing.

Summary

The following is a recap on what we learned in this chapter:
  • The Unity Hub program will be used to download new versions of the Unity editor, uninstall old versions you no longer need, create new projects, and open existing projects.

  • Opening a project in the Unity Hub will start the Unity editor, which is where we’ll actually use the engine to develop our game.

  • A Unity game project is stored on your computer, with all the related files – including stuff we make ourselves like art and code – stored in a “root directory” named after the project name.

  • Our code will be written with Visual Studio Code, a text editor designed specifically for writing code. It will offer us useful features that normal text editors don’t have, making it easier to format and navigate our code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.249.104