I’m trying to build a top-down game where I have this flashlight, and well I need all the room to be visible but for example the enemies should be hidden but they can emit sound so you are like where they are? and you have to look with the flashlight, the thing is that I don’t know how to make them invisible until the light hits them
Make a simple polygon trigger and set the enemies to enable their renderer when the enemies enter the trigger and disable it when they leave the trigger. For example (on the enemy script)
I made field of view using a Polygon collider shaped as a cone and simply alerted the enemy if the player entered the trigger and started a cool down timer if the player left the collider.
So after 15 seconds the enemies stop chasing the player anymore and switch to a search mode where they simply are alerted and search around for the player.
And I switched between three different cones depending on the AI state of the enemy, a smaller one for idle/unaware, a medium one for searching and a huge one for alerted/chasing.
I forgot a step of my line of sight. When the player enters the collider I send a raycast every 0.5s to see if the enemy can see the player. Otherwise they will be able to detect the player through walls.