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:

  1. In Unity, create another C# Script and name it TalkToMe.
  2. Make a public string variable named hereItIs.
  3. Assign some text to hereItIs.
  4. Make a public method named MakeMeTalk().
  5. Have MakeMeTalk() output some text to the Console.
  6. Attach MakeMeTalk() to the Main Camera. Now the code should look something like this:
    Time for action – communicating with another Component on the Main Camera
  7. Modify LearningScript to retrieve the TalkToMe Component.
  8. Modify LearningScript to retrieve the data in hereItIs.
  9. 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.