Using Raycast to activate & deactivate script.

Hey guys,
So i have gameObjects with the same script attached to it that outlines the mesh, but i want to activate it when raycast hits and deactivate when it doesnt. The code i have below gives me an error:

if (Physics.Raycast (shootPoint.position, shootPoint.transform.forward, out hit, 4f)) {
if ( == “Handgun”) {
hit.collider.gameObject.GetComponentInChildren ().enabled = true;
} else
hit.collider.gameObject.GetComponentInChildren ().enabled = false;

Anyone have a solution to this?

Wouldn’t you want to write it like this?


How else would it know what component you are trying to enable or disable? Unless I’m mistaken or something. I think that should work fine.