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:
- In the Hierarchy tab, select the Main Camera GameObject.
- 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
- 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:
- 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
- By doing so, the Reference Manual automatically switches to the Scripting Reference:
Figure 1.23: Unity scripting documentation with SWITCH TO MANUAL
- 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:
- Unity Forum: https://forum.unity.com/
- Unity Answers: https://answers.unity.com/index.html
- Unity Discord: https://discord.com/invite/unity
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.