Basic Question: Making one object trigger a non-static method in multiple prefab Instances

Hi,

  • I have multiple instances of an enemy prefab in my game.
  • I have a different object that needs to trigger a method within these instances that checks whether the enemy is moving. If it is, the method will reduce it’s speed. If they’re not, the method will do nothing.

Question: Because the enemies are moving at different speeds, I cannot make the speed static within the enemy prefab script, and thus I also cannot make the method static. What is the correct way to use one script, to trigger a non-static method on multiple instances of a prefab?

I’m new to coding/Unity, so I hope that question makes sense. I can’t seem to find documentation on this anywhere so I may either be asking the question wrong, or missing something very obvious.

Thank you,
Joe

Figured it out. For the object that needed to call the method within my enemy prefab instances, I added a delegate. I then had my prefab subscribe to the delegate and “observe” whenever the other object invoked the change. This video was helpful: