O'Reilly logo

Mastering Unity Scripting by Alan Thorn

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

Component interactions

We've seen the anatomy of a GameObject as a collection of components and nothing more. This raises logistical issues about how components should interact and communicate with each other. Each component is effectively implemented as a self-contained script file, separate from any other component, yet a component must often interact with others. Specifically, you'll often need to access variables and call functions on other components on the same GameObject, and you might even need to do this on every frame. This section explores such intercomponent communication.

One way to call functions on other components is to use SendMessage and BroadcastMessage, as shown in Chapter 1, Unity C# Refresher. These functions are type agnostic. ...

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