Communication Breakdown
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.
Tell the enemy to call the method through script communication. The first example shows the enemy calling the method player. Damage.
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.
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.









