Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning C# by Developing Games with Unity

You're reading from   Learning C# by Developing Games with Unity Get to grips with coding in C# and build simple 3D games in Unity 2023 from the ground up

Arrow left icon
Product type Paperback
Published in Nov 2022
Publisher Packt
ISBN-13 9781837636877
Length 466 pages
Edition 7th Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Harrison Ferrone Harrison Ferrone
Author Profile Icon Harrison Ferrone
Harrison Ferrone
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Getting to Know Your Environment FREE CHAPTER 2. The Building Blocks of Programming 3. Diving into Variables, Types, and Methods 4. Control Flow and Collection Types 5. Working with Classes, Structs, and OOP 6. Getting Your Hands Dirty with Unity 7. Movement, Camera Controls, and Collisions 8. Scripting Game Mechanics 9. Basic AI and Enemy Behavior 10. Revisiting Types, Methods, and Classes 11. Specialized Collection Types and LINQ 12. Saving, Loading, and Serializing Data 13. Exploring Generics, Delegates, and Beyond 14. The Journey Continues 15. Pop Quiz Answers
16. Other Books You May Enjoy
17. Index

Getting started with Unity 2023

If you don’t have Unity installed (or are running an earlier version), follow these steps to set up your environment:

  1. Head over to https://www.unity.com/.
  2. Select Download (shown in Figure 1.1):

    Figure 1.1: Unity homepage

    To provide a complete view of the Unity editor, all our screenshots are taken in full-screen mode. For color versions of all book images, use the link below: https://packt.link/7yy5V.

  3. This will take you to the Unity store page. Don’t feel overwhelmed by this—you can download Unity completely for free!

    If the Unity homepage looks different for you than what you can see in Figure 1.1, you can go directly to https://store.unity.com.

  4. Scroll down to the How to get started section and download the Unity Hub application for either Windows or Mac, as shown in Figure 1.2. I’ll be using a Mac, but everything works the same on a Windows machine:

    Figure 1.2: Start creating with the Unity portal

  5. Once the download is complete, follow these steps:
    1. Open up the installer (by double-clicking it)
    2. Accept the user agreement
    3. Follow the installation instructions
  6. When you get the green light, go ahead and fire up the Unity Hub application!
    1. If Unity asks you to choose a license option, select the Personal license option (which is completely free) and follow the instructions to set up your account.
  7. The newest version of Unity Hub will prompt you to install the latest LTS (Long Term Support) version of Unity, as shown in Figure 1.3. If the default version is Unity 2023 or higher when you’re reading these instructions, select Install Unity Editor:

    Figure 1.3: Install Unity Editor window

  8. If Unity 2023 is not the default version when you’re reading this, select Skip installation in the bottom-right corner of Figure 1.4:

    Figure 1.4: Install wizard

  9. Switch to the Installs tab from the left-hand menu and select Install Editor, as shown in Figure 1.5:

    Figure 1.5: Unity Hub Installs panel

  10. On the Official releases tab, select your desired version of Unity, then click Install (Silicon for Macs, Intel for Windows). At the time of writing, Unity 2023 is listed under the OTHER VERSIONS section of the Official releases tab, but you should be able to select a 2023 version from the Official releases list by the time you’re reading this:

    Figure 1.6: Add Unity version pop-up window

  11. You’ll then be given the option to add various modules to your installation. Make sure the Visual Studio (for Mac or Windows accordingly) module is selected and click Continue:

    Figure 1.7: Adding install modules

  12. If you want to add any modules later, you can click the gear icon to the right of any installed version in the Installs window.

When the installation is complete, you’ll see a new version in your Installs panel, as follows:

Figure 1.8: Installs tab with Unity versions

You can find additional information and resources about the Unity Hub application at https://docs.unity3d.com/hub/manual/index.html.

There’s always a chance of something going wrong, so be sure to check the following section if you’re using macOS Catalina or later, which has been known to throw up issues.

Using macOS

If you’re working on a Mac with OS Catalina or later, there is a known issue when using some versions of Unity Hub to install Unity. If this is the case for you, take a deep breath, go to the Unity download archive, and grab the 2023 version you need (https://unity3d.com/get-unity/download/archive). Remember to use the Downloads (Mac) or Downloads (Win) option instead of the Unity Hub download:

Figure 1.9: Unity download archive

Once the installer application downloads, open it up and follow the setup instructions! All of the examples and screenshots for this book were created and captured using Unity 2023.1.5f1. If you’re using a newer version, things might look slightly different in the Unity Editor, but this shouldn’t affect your following along.

Now that Unity Hub and Unity 2023 are installed, it’s time to create a new project!

Creating a new project

Launch the Unity Hub application, which is your staging area—you can see a list of all your projects and Unity versions and access learning resources and community features here. Then, take the following steps:

  1. To get started, click on New project in the top-right corner:

    Figure 1.10: Unity Hub Projects panel

  2. Make sure the editor version at the top is set to your 2023 version and set the following fields:
    • Templates: The project will default to 3D Core
    • Project name: I’ll be calling mine Hero Born
    • Location: Wherever you’d like the project to be saved
  3. Once the settings have been configured, hit Create project:

    Figure 1.11: Unity Hub with New project configuration popup

With the project created, you’re all set to explore the Unity interface! You can re-open your project anytime from the Projects panel in Unity Hub, but if your computer is running a little slow with both Unity and Unity Hub open, feel free to close Unity Hub.

Navigating the editor

When the new project finishes initializing, you’ll see the glorious Unity Editor! I’ve marked the important tabs (or windows, if you prefer) in Figure 1.12:

Figure 1.12: Unity interface

This is a lot to take in, so we’ll look at each of these panels in more detail:

  1. The Toolbar panel is the topmost part of the Unity Editor. From here, you can sign in to a Unity account, manage services, access the Asset Store, collaborate with a team (far-left button group), and play and pause the game (the center buttons). The right-most button group contains a search feature, LayerMasks, and layout scheme features, which we won’t be using in this book because they don’t apply to learning C#.
  2. The Hierarchy window shows every item currently in the game scene. In the starter project, this is just the default camera and directional light, but when we create our prototype environment, this window will start to get filled in with the objects we create in the scene.
  3. The Game and Scene windows are the most visual aspects of the editor. Think of the Scene window as your stage, where you can move and arrange 2D and 3D objects. When you hit the Play button, the Game window will take over, rendering the Scene view and any programmed interactions. You can also use the Scene view when you’re in play mode.
  4. The Inspector window is your one-stop shop for viewing and editing the properties of objects in the scene. If you select Main Camera in the Hierarchy (highlighted in blue in the above screenshot), you’ll see several parts displayed, which Unity calls components—all of which are accessible from the Inspector.
  5. The Project window holds every asset that’s currently in your project. Think of this as a representation of your project’s folders and files.
  6. The Console window is where any output we want our scripts to print will show up. From here on out, if we talk about the console or debug output, this panel is where it will be displayed.

If any of these windows get closed by accident, you can re-open them anytime from the Unity menu > Window > General. You can find more in-depth breakdowns of each window’s functionality in the Unity docs at: https://docs.unity3d.com/Manual/UsingTheEditor.html.

Before continuing, it’s important that Visual Studio is set up as the script editor for your project. Go to the Unity menu > Preferences > External Tools and check that External Script Editor is set to Visual Studio for Mac (or Windows):

Figure 1.13: Changing External Script Editor to Visual Studio

As a final tip, if you want to switch between light and dark modes, go to the Unity menu > Preferences > General and change Editor Theme:

Figure 1.14: Unity general preferences panel

I know that was a lot to process if you’re new to Unity, but rest assured that any instructions going forward will always reference the necessary steps. I won’t leave you wondering what button to push. With that out of the way, let’s start creating some actual C# scripts.

You have been reading a chapter from
Learning C# by Developing Games with Unity - Seventh Edition
Published in: Nov 2022
Publisher: Packt
ISBN-13: 9781837636877
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime