Hey! I am trying to shoot a raycast from a UI image but I cannot figure out how to do so. I have tried using a graphic raycaster but I only was able to get it to shoot from my mouse position. I’ve attached an image to further show my issue, the red dot is where I need the ray to be shot from and the blue arrow is the direction it needs to go. Does anyone know of any solutions?
Vector3 screenPoint = yourMainCamera.WorldToScreenPoint(yourRedDotTransform.position);
Ray aimRay = yourMainCamera.ScreenPointToRay(screenPoint);
Physics.Raycast(aimRay, out var hit, _maxRayDistance);
// Do something with hit object
The idea is to convert your reddot position in scene into position in screen, then use screen position to do raycast