You can use a dynamically generated mesh. The points for the mesh can be obtained using one of the techniques described in the links from the comments. Those steps are as follows:
- Collect all the objects in your vision cone. This depends on what you’re using for your vision cone and underlying data structure for keeping track of your objects. You could use a collider for your vision cone and maintain a list of objects using OnTriggerEnter and OnTriggerExit, or you could do a
- For each object
- Get the points that define the object’s collider, or otherwise find the edges of the collider.
- For each point
- Cast a ray from your vision cone source through the point to the edge of your vision cone.
- Wherever the ray hits, add that point to your mesh.
- Cast two additional rays +- a small amount to either side of the point. Also add these hit points to your mesh.
The result ends up looking something like this:
Each line is a ray cast and each point is a place where ray cast hit. The points hitting along the center of geometry are rays that were meant for end points farther away, but hit something along the way.
Finally, complete the mesh, fanning out from the center point to each point around the vision cone.