Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Learning C# by Developing Games with Unity
  • Toc
  • feedback
Learning C# by Developing Games with Unity

Learning C# by Developing Games with Unity

By : Harrison Ferrone
4.4 (47)
close
Learning C# by Developing Games with Unity

Learning C# by Developing Games with Unity

4.4 (47)
By: Harrison Ferrone

Overview of this book

It's the ability to write custom C# scripts for behaviors and game mechanics that really takes Unity the extra mile. That's where this book can help you as a new programmer! Harrison Ferrone, in this seventh edition of the bestselling series will take you through the building blocks of programming and the C# language from scratch while building a fun and playable game prototype in Unity. This book will teach you the fundamentals of OOPs, basic concepts of C#, and Unity engine with lots of code samples, exercises and tips to go beyond the book with your work. You will write C# scripts for simple game mechanics, perform procedural programming, and add complexity to your games by introducing intelligent enemies and damage-dealing projectiles. You will explore the fundamentals of Unity game development, including game design, lighting basics, player movement, camera controls, collisions, and more with every passing chapter. Note: The screenshots in the book display the Unity editor in full-screen mode for a comprehensive view. Users can easily reference color versions of images by downloading them from the GitHub repository or the graphics bundle linked in the book.
Table of Contents (18 chapters)
close
15
Pop Quiz Answers
16
Other Books You May Enjoy
17
Index

Exploring the documentation

The last topic we’ll touch on in this first foray into Unity and C# scripts is documentation. Not sexy, I know, but it’s important to form good habits early when dealing with new programming languages or development environments.

Accessing Unity’s documentation

Once you start writing scripts in earnest, you’ll be using Unity’s documentation quite often, so it’s beneficial to know how to access it early on. The Reference Manual will give you an overview of a component or topic, while specific programming examples can be found in the Scripting Reference.

Every GameObject (an item in the Hierarchy window) in a scene has a Transform component that controls its Position, Rotation, and Scale. To keep things simple, we’ll just look up the camera’s Transform component in the Reference Manual:

  1. In the Hierarchy tab, select the Main Camera GameObject.
  2. Move over to the Inspector tab and click on the information icon (question mark, ?) at the top right of the Transform component:

    Figure 1.20: Main Camera GameObject selected in the Inspector

  3. You’ll see a web browser open on the Transforms page of the Reference Manual:

    Figure 1.21: Unity Reference Manual

All the components in Unity have this feature, so if you ever want to know more about how something works, you know what to do.

So, we’ve got the Reference Manual open, but what if we wanted concrete coding examples related to the Transform component? It’s pretty simple—all we need to do is ask the Scripting Reference:

  1. Click on the SWITCH TO SCRIPTING link underneath the component or class name (Transforms, in this case):

    Figure 1.22: Unity Reference Manual with the SWITCH TO SCRIPTING button highlighted

  2. By doing so, the Reference Manual automatically switches to the Scripting Reference:

    Figure 1.23: Unity scripting documentation with SWITCH TO MANUAL

  3. As you can see, as well as coding help, there is also an option to switch back to the Reference Manual if necessary.

The Scripting Reference is a large document because it has to be. However, this doesn’t mean you have to memorize it or even be familiar with all of its information to start writing scripts. As the name suggests, it’s a reference, not a test.

If you find yourself lost in the documentation, or just out of ideas regarding where to look, you can also find solutions within the rich Unity development community in the following places:

On the other side of things, you’ll need to know where to find resources on any C# question, which we’ll cover next.

Locating C# resources

Now that we’ve got our Unity resources taken care of, let’s take a look at some of Microsoft’s C# resources. For starters, the Microsoft Learn documentation at https://docs.microsoft.com/en-us/dotnet/csharp has a ton of great tutorials, quick start guides, and how-to articles. You can also find great overviews of individual C# topics at: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/index.

However, if you want detailed information on a specific C# language feature, the reference guides are the place to go. These reference guides are an important resource for any C# programmer, but since they aren’t always the easiest to navigate, let’s take a few minutes to learn how to find what we’re looking for.

Let’s load up the programming guide link (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/index) and scroll down to Language Sections and click on the Strings link directly:

Figure 1.24: Navigating Microsoft’s C# reference guide

You should see something like the following for the class description page:

Figure 1.25: Microsoft’s Strings (C# Programming Guide) page

Unlike Unity’s documentation, the C# reference and scripting information is all bundled up into one, but its saving grace is the subtopic list on the right-hand side. Use it well! It’s extremely important to know where to find help when you’re stuck or have a question, so be sure to circle back to this section whenever you hit a roadblock.

bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete