How to communicate between scripts

Objective: Use the GameObject.Find method.

Let’s connect two scripts together. We will reach out to another function in another script that will then turn off the spawn after the player dies.

We begin by setting in our player the ability to connect to the spawn manager to get the spawn manager component.

We then want to do a check where if the player dies, we want to do a OnPlayerDeath() function. When we run this function, we want to use our handle to the spawn manager and run a new function in the spawn manager called StopSpawning().

Our new function simply turns off the spawn capabilities. This shuts off all future spawn potential.


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ