如何将相机旋转到鼠标单击

时间:2015-12-01 10:17:31

标签: unity3d mouse

我查看模型(使用Unity3d)。现在我与模型进行鼠标交互。如何将相机旋转到鼠标点击位置。 http://prntscr.com/990q9y

2 个答案:

答案 0 :(得分:0)

也许是这样的?

你想要“点击”,对吗? 哦,你想改变相机。

if (Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 if (Physics.Raycast(ray, out hit))
                 {
                   Camera.main.transform.localEulerAngles=hit.point;
                 } 
         }

//or try to fix the z thing:
if (Input.GetMouseButtonDown(0))
             {
                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                 Camera.main.transform.localEulerAngles = ray.origin + (ray.direction * 4.5f);
             }

我在这里看到:http://answers.unity3d.com/questions/376735/get-world-coordinates-from-mouse-click.html

也许这可以帮到你很多:How to constrain rotation from mouse input in unity 5?

答案 1 :(得分:0)

此代码可以正常工作,但是如何顺利旋转?

if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
var pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
transform.transform.LookAt(hit.point);
player.UpdatePosition();
}
}