Let a trigger on Prefab communicate with parent

Hi, new to Unity C Scripting, am stuck, just need pointers, appreciated, thanks.

I’m making an autonomous prefab & duplicate -enemy with an inside-prefab child object that has a trigger and I want the inside-prefab parent to understand that it should act when it’s child’s trigger is triggered.

So, I need to communicate between the two.

QUESTION: Which method would be the optimal for such communication?

Thank you very, very much :slight_smile:

2 Answers

2

I would add a reference to the parent object in the child object script. Then call a function in the parent.

If you don’t know how far up you need to go then a combination of SendMessageUpwards and BroadCastMessage works

Thanks, However I think that'll be more resource demanding/less optimal than wijesijp's suggestion - and be more sloppy in general.. I think :) ?

It is more resource demanding. I put it up as a plausible alternative if for some reason you can't get a reference to the parent object. If you can get a reference you should use it.