
Learning C# by Developing Games with Unity 3D Beginner's Guide
By :

Let's look at accessing a variable in LearningScript
from inside LearningScript
.
Modify LearningScript
as shown in the following figure:
Save the file.
In Unity, click on Play.
Here are the outputs in the Console:
An analysis of the code shown in the previous code screenshot is as follows:
Line 6: string myString = "Access the variable ";
myString
is the variable that will be accessed
Notice that it's private
by default, yet it can still be accessed
Line 17: Debug.Log(myString + "the normal way.");
This is how we have been accessing the value stored in a variable, by just using the variable name
The string
value in myString
, Accessing this variable
, is substituted for the variable name
myString
is being accessed without using Dot Syntax or GetComponent()
, because a script always has access to its own variables and methods
Line 18: Debug.Log(this.myString + "using 'this' keyword.");
myString
is being accessed using...
Change the font size
Change margin width
Change background colour