Not sure I am getting the question right but there is already a built in function for that
If you explain what you are trying to achieve as a higher level question we can be more helpfull cause there is bunchof integrated functionality regarding ScreenToWorld detection, such as location, objects traces etc.