Time for action – communicating with another Component on the Main Camera
Let's create another script with a variable and a method, and attach it to the Main Camera, then have LearningScript
communicate with it:
- In Unity, create another C# Script and name it
TalkToMe
. - Make a
public
string
variable namedhereItIs
. - Assign some text to
hereItIs
. - Make a
public
method namedMakeMeTalk()
. - Have
MakeMeTalk()
output some text to the Console. - Attach
MakeMeTalk()
to the Main Camera. Now the code should look something like this: - Modify
LearningScript
to retrieve theTalkToMe
Component. - Modify
LearningScript
to retrieve the data inhereItIs.
- Modify
LearningScript
to ...
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.