raycast and detecting objects

I have an object that needs to know when it has been touched by my raycast. How can I do this? Been looking everywhere but haven’t found any information on this :frowning:

Let your raycast “out” a RaycastHit. this will contain the collider which it hit. Then just GetComponent<> on the collider to find your script and call methods on that object.

RaycastHit hit;
if(Physics.Raycast(Ray/position + direction, out hit))
{
hit.collider.gameObject.GetComponent<MyScriptWhichNeedToKnowWhenRaycastHitsIt>().RaycastHitYou();
}

That did it! Thank you! :slight_smile: