Unity3D 物體跟隨鼠標移動

方法一(直接獲取 Input.mousePositon):

將Camera設置爲正交模式。

target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.y = ChessPiece.transform.position.y;
ChessPiece.transform.position = target;

注:將其中一個座標修改爲物體自帶的。因爲轉換出來的座標中,有一維是錯誤的,具體是哪一維,看具體情況。

 

方法二(碰撞射線):

將Camera設置爲透視模式。

https://blog.csdn.net/xufeng0991/article/details/52254502 (轉)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章