get world position from mouse click unity code example

Example 1: unity mouse position to world

Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

Example 2: unity mouse world position

//check for Left mouse Key 
if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
            {
				//hit.point is the position, where the Raycast from the camera
              	//position towards the ground hit the first collider
                Vector3 positionInWorld = hit.point; 
              
              	//Do something with positionInWorld here...
               
            }
        }