Best practice for robot scanning light.

Pretty new here.

We’re working on a 2.5D platformer. We have a character running along and an enemy in the background (different depth) that has a light that scans back and forth along the playing pane. If the character steps into the light, this will alert the guards (standard fair).

So I’ve got a game object representing the enemy in the background rotating right and left and i’ve got a simple game object on the players pane with a box collider set to trigger moving right and left. My question is what’s the best way to pair these. The options I’ve considered:

  1. Child the trigger collider to the enemy and reset it’s z-position every update frame.
  2. Keep them as separate object and have one hold a reference to the other, so:
    a. Have the trigger hold the enemy and update itself according to the enemy’s rotation.
    b. Have the enemy keep track of the trigger and actually make the trigger be the thing that is moving.

Of course, other suggestions I may not have thought of are more than welcome!

So really it’s a logical design question. As this is currently the most complicated thing I’ve ever done in Unity (like I said, pretty new), I want to make sure I understand the thinking behind design in the engine correctly.

Thanks!

Restricting the design to one of those two options, the answer would only really be which one would be “more work” to implement.

Without seeing your entire project, it’d be hard to give any kind of precise estimate, but my best guess would be the first option would be easier and cheaper for the system, since it wouldn’t need to update rotations a second time, in one frame, and both options require you to move the end of the trigger collider about the z-axis, anyway, if they are to collide properly.