Hello,
I’m new in Unity.
I would like to get the 2D mouse coordinates relative to the scene.
With this code I get the mouse coordinates relative to the camera: Input.mousePosition
The origin is in the left bottom corner.
I would like to set the potition of one sprite to the mouse coordinates :
gameObject.transform.position = Input.mousePosition;
But that doesn’t work :-/.
Any ideas ?
Thanks
Have the same problem, Needs charecter move by mouse press tried this transform.Translate(Input.mousePosition * Time.deltaTime); didn’t worked 
popc
3
Use Camera.ViewportToWorldPoint.
[Edit]
quarag is right.
quarag
4
Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
pz.z = 0;
gameObject.transform.position = pz;
11 Likes
Does anyone know what to do to make a 2d character follow the mouse without clicking anything
What does ‘pz.z = 0;’ mean?
Please don’t necro threads like this. This post is 7 years old.
I’ll move this thread to the scripting forum where it belongs.