Here is a much simplified way to get Input.mousePosition to World Units

Vector2 CalculateWorldPointOfMouseClick()
{
    return myCamera.ScreenToWorldPoint(Input.mousePosition);  
}

I was using that too, but then I remembered from the LaserDefender videos that we should stay in the habit of using Vector3 and camera distance when using myCamera.ScreenToWorldPoint since it actually creates a foundation for using that in 3D games later on. I guess it doesn’t make any difference in a 2D game so it’s probably fine to use it. Nevertheless, it’s probably good to not form a bad habit that will lead to bad coding later down the road.

1 Like