Unity3D Basics — GetComponent and Script Communication

Claudio Grassi
4 min readMar 31, 2021

Unity is a modular system that relies on Components to define the attributes and behaviors of GameObjects. Most of these Components have values that are accessible to us to manipulate either while we are designing our game or during runtime.

Script Communication is a term that defines the ability to allow separate Scripts to interact. When we wish to define behavior based on conditions that our player or game might run into, we can take advantage of this process to react in whichever way we wish.

To do this, we can make use of Unity’s GetComponent() method.

This Generic version of the public method allows us to retrieve a Component from a GameObject based on its Type<T> and it returns NULL if it is not found.

OBJECTIVE:

Apply the Script Communication technique to inform our GameManager Script when the player dies to initiate our game over sequence.

METHOD:

Let’s begin by writing our GameManager Class.

--

--

Claudio Grassi

Experienced digital artist, Unity game developer & coder with a knack for problem solving and a passion for video games.