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);
}