Detecting a trigger... "remotely?"

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?

Hello,
Can you use

var other : Transform;
if (other) {
    var dist = Vector3.Distance(other.position, transform.position);
    print ("Distance to other: " + dist);
}

the Nature Demo has a flocking script I believe then you can use the FPS Waypoint script to attack the player

Ray

I can’t seem to find the Nature Demo (from what I can tell it predates the island demo and showcased different elements of Unity).

Opps, sorry that’s what I meant to say,
Island Demo :smile:

Ray