Getting mouse position in unity

后端 未结 4 2162
感情败类
感情败类 2020-12-11 03:32

I\'m trying to move a object to the mouse position. But it\'s giving me large x value like 300 but at that place the pre placed object\'s x position is -4.

         


        
4条回答
  •  -上瘾入骨i
    2020-12-11 03:48

    The conversion with ScreenToWorldPoint is straight-forward for 2D Vectors:

        Vector2 screenPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        Vector2 worldPosition = Camera.main.ScreenToWorldPoint(screenPosition);
    

提交回复
热议问题