Using Dot Syntax in a script

Now that you know that each Component object resides in computer memory, storing data in variables, it's time to use Dot Syntax to access those Component variables and methods.

Accessing a Component's own variables and methods

Dot Syntax can be used to access any pubic variable or method on any Component on any GameObject. Even though a Component always has access to its own variables and methods, we can still use Dot Syntax if we want.

In order to have access to a variable or method, we have to know its location. Let's start by looking in LearningScript.

Here's an overview of how to access a variable or method from within the current Component:

Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.