Parameter error in Physics.Raycast(ray, out RaycastHit)

Hello.
I wanna get the touched object, but Raycast method is having error just as the image.
I don’t understand why… because this is the way it’s written on the unity api document.
Thanks in advance.

I see a “ScreenT” in your code! Are you using Camera.ScreenToWorldPoint? Because if you are, it returns Vector3, and you are passing a Vector3 as the first parameter for Physics.Raycast, which causes the Physics.Raycast method code to depend on a next parameter to be a direction, as said in Physics.Raycast documentation.

Basically, you are calling the following overload if you use Camera.ScreenToWorldPoint, which causes the error, because the second parameter should be the direction:

Physics.Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layerMask, QueryTriggerInteraction queryTriggerInteraction)

And you are trying to replace direction with “out hit”. Try Camera.ScreenPointToRay and use the following Physics.Raycast overload:

Physics.Raycast(Ray ray, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);