how do i write the event part

From the RaycastHit you can get the collider.

From the collider you can call .GetComponent() to get any particular script off the thing you raycasted into.

Be sure to test what you get back for being null before blindly using it.

For future reference:

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

2 Likes