How can I get an object reference from a Raycast?

So I want to deactivate some houses I have in my level when the player goes behind them, by using a raycast. I shoot the raycast from the camera onto the player and check for things in between but I don’t know how I can get the object reference so I’m able to deactivate the houses. Please help me. Thank you :slight_smile:

Vector3 start =;
Vector3 direction = Vector3.forward;
RaycastHit hit;
if(Physics.Raycast(start, direction, out hit))

Physics Raycast gives you a reference to the collider, which was hit. It is stored in the out parameter as a RaycastHit. You can get information about the hit itself, the collider, transform, gameobject and so on from that hit variable.