I’m doing a platforming game. I have an bird monster that should attack the player if the player enters its territory, and once the player leaves the bird will return to its nest. I want to have a bunch of these birds throughout the level. The bird is a rigidbody, and the nest is just a mesh, and the territory is a gameObject with a trigger-collider.
I know how to give the territory-object a script that would flip a static variable when the player enters, and then have the bird’s script respond to the variable change to tell it to attack or return to the nest. But wouldn’t I then need a whole bunch of static variables I’d have to keep updating each time I added a new bird/nest/territory instance?
So it seems like there should be a way for the bird script to remotely detect that the player has entered the territory collider, and respond accordingly. Then each time I created a new instance I’d just have to plug in which Territory I want the bird to look at. But all the examples of trigger collisions (OnTriggerEnter, etc) seem to assume that that they will be placed in a script for the trigger-zone in question.
Is there a way to do what I’m trying to do? Am I even making sense?