Time for action – trying drag-and-drop to assign a GameObject
Let's change a few lines of code in LearningScript
to show how to assign the Capsule GameObject to the variable capsuleGO
using drag-and-drop.
Either comment out line 11 using 2 forward slashes (
//
), or remove it.On line 6, add the access modifier
public
like this:public GameObject capsuleGO;
Save the file.
In Unity, select the Main Camera GameObject.
Drag the Capsule to the Capsule GO field in the Inspector. The following screenshot shows how this is done.
Click on Play.

What just happened?
The Capsule GameObject is now assigned to the capsuleGO
variable. We didn't have to write the code because Unity has done the assignment internally for us. Also, this doesn't change LearningScript
in any way.
Pop quiz – understanding communication between objects
Q1. What is Dot Syntax, and what does it allow you to do?
Q2. When an object is assigned to a variable, what is actually stored in the variable?
Q3. Are there any limits to using Dot Syntax...