I'm making a 2D top-down survival game similar to Rimworld
, I'm trying to emulate a day-night system.
Many features depend on whether any tile is light (or dark) enough, based on time of day or other light sources such as torches, so I'm wondering if there's an easy way to detect how much light there is on a certain tile without making a whole system that tracks light on a per-tile level (or maybe the latter option is better)?
I am using Unity 2020.3.6f1
and the URP
, which means I'm going to be using the 'new' 2D lights.
EXAMPLE: When it's nighttime, I'm going to disable the global light (sun) so those tiles will be pitch black. When it's daytime, the global light will have an intensity of 1 so that tile will have 100% brightness (look normal). When it's nighttime, but there's a torch, the tile where the torch is sitting on will have 100% brightness, and that will slowly fade to 0% over a span of 5 tiles.
Making a system that updates every single tile in the game with information about the light level seems pretty expensive. Is there a way we can observe a block "graphically", or in other words, literally look at the pixel on the screen, and determine it's alpha value to check for light level?
Any suggestion is super welcome.
EDIT: Every tile does not need to know its brightness every frame, but they do need to know it less often. Some examples are:
- A plant checking every couple of frames to see if it can grow
- A character checking every couple of frames to see if he's in the dark (and if he is, he needs to start panicking)
More importantly, I need my characters to make decisions based on light amount. For an example, if there is a job that needs to be done at a certain location, a character should first check the light level of that location before going to do it.
R * 0.21 + G * 0.72 + B * 0.07
). \$\endgroup\$