Enable renderer when in line of sight

Hi, I’m currently trying to pull off enabling a renderer of an object when it’s in line of sight of the object. I wouldn’t really know how to pull this off. I’ve tried Raycasting which still seems like the most plausible salution, but I can’t get it to cast in a 360 radius. Does anyone encountered the same problem before?

Example:
Left: Blue square is the player, enemy currently not visible.
Right: Enemy is now visible.

22318-untitled-1.jpg

You shouldn’t need to cast 360 - just cast from the player’s position to the enemy’s position and see if you get there (hit the enemy, not something else first).

Use a raycast as following:

  • orgin: one of the 2 squares, the square u didnt chose shall be named “othersquare”. Now the direction will be: othersquare.transform.position - transform.position.

Now just do a Physics.raycast check, if thr raycast returns anothet object than the othersquare, disable the renderer!

Ps: sorry i coulnd write the code im on my train back home, typing on my phone