Screentoworldpoint not working correctly?

I have a gameobject that follows the mouse after it is bought and when you click the mouse it places. I have the camera rotated a little to 45 degrees and when trying to place the object the mouse moves up on the screen and the object doesn’t move where the mouse is. It only works if the camera is at 90 degrees looking down at the object. How could I make the object continue to follow the mouse using screentoworld point without worring about rotation of the camera? Thank you!!

void Update()
	{
Vector3 m = Input.mousePosition;
		m = new Vector3  (m.x, m.y, transform.position.y);

		Camera camera = GetComponent<Camera>();
		Vector3 p = camera.ScreenToWorldPoint(m);

		if (currentBuilding != null && !hasPlaced)
			{
				
			currentBuilding.transform.position = new Vector3 ( p.x,0, p.z);
}

ScreenToWorldPoint does work correctly. You have to provide appropriate values; using transform.position.y for the z distance doesn’t make much sense. Instead, specify the distance from the camera to where you want the object placed (in world space units). e.g., (m.x, m.y, 10.0f) would use a distance of 10 units in the camera’s forward direction, regardless of how it’s rotated.