ray hit mouse click position unity code example
Example 1: unity ray from mouse position
RaycastHit hit;
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)) {
Transform objectHit = hit.transform;
// Do something with the object that was hit by the raycast.
}
Example 2: unity mouse click screen
var cameraloc:Camera;
var mousePos:Vector3;
var worldPos:Vector3;
cameraloc = GameObject.Find("Camera").GetComponent(Camera);
mousePos = Input.mousePosition;
worldPos = cameraloc.ScreenToWorldPoint(mousePos);