Inter-script communication and Dot Syntax
In order to create games effectively, you'll often need to communicate between scripts in order to pass data around, adjust variables, and call functions in external scripts—by external here we can mean either a separate script or one attached to a different object than the given script.
Accessing other objects
Often you may be in a situation where your script is located on one object, and you wish to communicate with a script on another object—for example, your player character may shoot an enemy and this results in the need for their health to decrease, but each enemy has an independent script storing its own health, so a script on the player or bullet must address the script on the enemy that its health ...
Get Unity 3.x Game Development Essentials 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.