Help me to undrstand the script

i am using the below script,it s working fine.but i want to know y we must calculating distance and y mot using input.mouseposition.z,???

i am confused help me

if (Input.GetMouseButtonDown(0)) {
float distance = transform.position.z - Camera.main.transform.position.z;
targetPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
targetPos = Camera.main.ScreenToWorldPoint(targetPos);
}

transform.position = Vector3.MoveTowards (transform.position, targetPos, speed * Time.deltaTime);
}

Please use code tags whenever you show code:

The mouse position only contains x and y coordinates, which is just the position of you mouse on the screen. Not more, not less. Everything else needs to be computed. You can use a method as described or use raycasting or even something else.
In general it doesn’t even make sense to provide a z coordinate, because it would just be misleading and confusing.

Thanks for ur reply.

what is the use of screenpointtoworldpoint?

It translates screen coordinates to world coordinates…

what is mean by screen coordinates? and world coordinates?

Screen space is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth,pixelHeight).

World space is an actual 3d position.

thanks fr ur reply