Script Communication

When the life of the player is '0', we know that the boolean "isGameOver" is set to "true" in PlayerController.cs script. Now, the first thing I would like to do when isGameOver == true is to stop the movement of the objects. For this we need to let the MoveObjects.cs script know what is happening in our PlayerController.cs script. This is achieved with script communication.

Script Communication

Script Communication Workflow

playerControllerScript = GameObject.Find("Player") ....

public GameObject gameObjectWithScript;


The final step is to get the component and store is to our variable playerControllerScript declared in the Start() method.

OR

MoveObject.cs Script

Now that we have a variable that we can use to communicate with our PlayerController script, I can move the objects only if the boolean isGameOver is set to true in PlayerController.cs.

A practical implication of access modifier can be seen in this process. In next section, I will talk about what access modifier is and how it affects the accessibility level in the script.