I am trying to trigger a function of an object through raycast detection, that is, I press the mouse on the screen, create a Raycast2D and detect if it collides with a 2D object, and if that happens trigger a function inside that object, for Give an example: change_color(), destroy_object(), etc. From now, thank you for your attention.
Yes, it is possible, once you have stored the information from the Raycast you can use it
SendMessage("nombre_funcion")
to execute a function that is in the Script of the object with which you have collided. Be careful, you will have to check first that the object with which your Raycast has collided is the object that contains the function you want to call, otherwise it will throw an Exception.If you share the code where you implement your Raycast2D I could give you a more concrete example, but here is an example of general use: