Question by
giraffeman3125 · May 14, 2020 at 08:56 PM ·
c#2d2d gamemousepositionz axis
Z position moving in 2D space
I am trying to make a system to move a sprite around in 2D space by getting the mouse X and Y, but the sprite is moving around in the Z axis causing the sprite to not be visible. My code is,
player.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, 0.0f));
(It should be all in one line but it isn't.) Please help.
Comment
Answer by wewewu · May 16, 2020 at 12:42 PM
This should work:
transform.position = (Vector2) Camera.main.ScreenToWorldPoint(Input.mousePosition);
You may leave out (Vector2)
.