官术网_书友最值得收藏!

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.

Time for action – opening the Reference Manual

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 object.
  2. Move over to the Inspector tab and click on the information icon (question mark) at the top-right of the Transform component:

You'll see a web browser open on the Transform page of the 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:

Time for action – using the Scripting Reference

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 Scripting API, or the Switch to Scripting link underneath the component or class name (Transform, in this case).

By doing this, the Reference Manual automatically switches to the Scripting Reference for the Transform component:

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# documents at https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/index.

There's a ton of other C# resources, ranging from tutorials and quickstart guides to version specifications (if you're into that), all of which are available at https://docs.microsoft.com/en-us/dotnet/csharp.

Time for action – looking up a C# class

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:

You should see something like the following for the class description 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. 

主站蜘蛛池模板: 宜良县| 绥棱县| 兴仁县| 嘉义县| 濮阳县| 伊金霍洛旗| 桃源县| 临清市| 承德县| 石家庄市| 盐津县| 永胜县| 安达市| 克拉玛依市| 泰州市| 屏边| 三亚市| 淮阳县| 白水县| 东平县| 龙门县| 南宫市| 独山县| 尤溪县| 远安县| 新龙县| 揭西县| 申扎县| 临沧市| 上虞市| 望谟县| 涪陵区| 洛浦县| 长泰县| 西吉县| 红原县| 元谋县| 习水县| 武功县| 黔西县| 岳阳县|