Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning C# by Developing Games with Unity - Seventh Edition

You're reading from  Learning C# by Developing Games with Unity - Seventh Edition

Product type Book
Published in Nov 2022
Publisher Packt
ISBN-13 9781837636877
Pages 466 pages
Edition 7th Edition
Languages
Author (1):
Harrison Ferrone Harrison Ferrone
Profile icon Harrison Ferrone

Table of Contents (18) Chapters

Preface 1. Getting to Know Your Environment 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

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.21: Main Camera GameObject selected in the Inspector

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

Figure 1.22: 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.23: Unity Reference Manual with the SWITCH TO SCRIPTING button highlighted

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

Figure 1.24: Unity scripting documentation with SWITCH TO MANUAL

  1. 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 and look up the C# String class. Do either of the following:

  • Enter Strings in the search bar in the top-left corner of the web page
  • Scroll down to Language Sections and click on the Strings link directly:

Figure 1.25: Navigating Microsoft’s C# reference guide

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

Figure 1.26: 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.

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 €14.99/month. Cancel anytime}