Sitemap
Lana Elfstrom

Lana Elfstrom

Game Developer

Communication Breakdown

2 min readDec 6, 2022
Press enter or click to view image in full size

The only component we have direct contact with is the transform. To access the other components, use getComponent. First we access the object, then tell Unity which component we are looking for.

In this instance, we are looking for player component. It holds a reference to the player because we tagged an object as “player”. It will only be called if we hit an object tagged as “player”.

Get Lana Elfstrom’s stories in your inbox

Join Medium for free to get updates from this writer.

Press enter or click to view image in full size

Tell the enemy to call the method through script communication. The first example shows the enemy calling the method player. Damage.

Press enter or click to view image in full size

Second example player communicates with spawn manager to turn on/off through a variable or method that controls the spawn manager variable without directly modifying the value of that variable.

Press enter or click to view image in full size

Calling a method on an non-existent object or component returns an error. Does the other object that collided with us have a player component? Null check the component — store in a reference variable of type. Best practice for clean code and avoiding erors.

--

--