Security Camera Scripts?

Hi.
I’m creating a watchdog-esque stealth game where you do stuff undetected by the enemies.
I am creating a camera system that detects the player, but for ray casting, I want to have a perspective view, and I want the ray cast to not go through walls.
How can I create a camera script to do this?
Thanks. All helps will be appreciated.

You should just need to do a raycast from the camera in the direction of the player and inspect the hit results. If there is a wall in front of the player, then that will be your hit result (assuming that the raycast is configured to collide with whatever layer the wall is on).

You probably don’t want to be doing this all the time though, so I’d suggest setting up a tirgger box on the camera which, when the player enters / stays within the trigger a ray is fired between the camera and the player.

Raycast info: Unity - Scripting API: RaycastHit