O'Reilly logo

Learning C# by Developing Games with Unity 3D Beginner's Guide by Terry Norton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required