unity-game-engine2dlight

How to know if an object is "lit" in Unity 2D


I want to know if an object is currently "lit", so I want to detect if the light source hits it.

I thought of a trigger as big as the light but I think that it would be quite annoying to put a specific collider for every light (I would need to modify the collider to adapt it to other light "shapes"). Is there a way / a better way than mine?


Solution

  • Yes, your way is probably the best way depending on how accurately you want to detect if an object is lit.

    If you have many different, or even randomly generated, light shapes, you could create a script that, in the Awake method, sets the collider's size/shape automatically.