Unity3d 摄影机聚焦对象中心

Unity3d 摄影机聚焦对象中心,unity3d,Unity3d,在我的代码中拾取对象的精确中心位置我在该函数中使用onmousedown函数拾取我希望在屏幕中使对象居中的单击位置 private void OnMouseDown() { Camera.main.GetComponent<PanZoom>().thisGameObject = ParentThis.gameObject; if (_center) {

在我的代码中拾取对象的精确中心位置我在该函数中使用onmousedown函数拾取我希望在屏幕中使对象居中的单击位置

private void OnMouseDown()
        {
           
        Camera.main.GetComponent<PanZoom>().thisGameObject = ParentThis.gameObject;
        if (_center)
        {
           
            Debug.Log("Show Popup");
            Popup.SetActive(true);
           
        }
        else
        {
            Vector3 groundPos = GetWorldPosAtViewportPoint(.5f, .5f);
          
            Debug.Log(groundPos);


            Debug.Log("groundPos: " + groundPos);
            groundCamOffset = Camera.main.transform.position - groundPos;
            Debug.Log("Camera pos " + Camera.main.transform.position);
            camTarget = Camera.main.transform.position;
           
            float mouseX = Input.mousePosition.x / Camera.main.pixelWidth;
            
            float mouseY = Input.mousePosition.y / Camera.main.pixelHeight;
         
            Debug.Log("Mousex " + Input.mousePosition.x + " : " + Camera.main.pixelWidth + " Mousey " + Input.mousePosition.y + " : " + Camera.main.pixelHeight);
            Debug.Log("Mx " + ParentThis.transform.localPosition.x + " My " + ParentThis.transform.localPosition.y);
            Vector3 clickPt = GetWorldPosAtViewportPoint(mouseX, mouseY);
            
            camTarget = clickPt + groundCamOffset;
        
            Go = true; // For Camera movement //!?
        }
    }
private void OnMouseDown()
{
Camera.main.GetComponent().thisGameObject=ParentThis.gameObject;
如果(_中心)
{
Log(“显示弹出窗口”);
Popup.SetActive(true);
}
其他的
{
Vector3 groundPos=GetWorldPosAtViewportPoint(.5f、.5f);
调试日志(groundPos);
调试日志(“groundPos:+groundPos”);
groundCamOffset=Camera.main.transform.position-groundPos;
调试日志(“摄像头位置”+摄像头.main.transform.position);
camTarget=Camera.main.transform.position;
float mouseX=Input.mousePosition.x/Camera.main.pixelWidth;
float mouseY=Input.mousePosition.y/Camera.main.pixelHeight;
Debug.Log(“Mousex”+Input.mousePosition.x+”:“+Camera.main.pixelWidth+“Mousey”+Input.mousePosition.y+”:“+Camera.main.pixelHeight);
Log(“Mx”+ParentThis.transform.localPosition.x+“My”+ParentThis.transform.localPosition.y);
Vector3 clickPt=GetWorldPosAtViewportPoint(mouseX,mouseY);
camTarget=点击PT+地面CamOffset;
Go=true;//用于相机移动//!?
}
}

在这种情况下,我建议您阅读更多关于它的内容,因为它具有可以进行更改的功能。请注意,Cinemachine必须首先通过Unity中的软件包管理器安装


因此,当我收集信息时,您希望将对象移动到鼠标单击的位置。这是正确的吗?或者是你,在被点击的物体上,想把物体放在你要检查的屏幕的中心吗?我想我点击任何物体的任何地方相机可以聚焦物体的中心,而不是点击时的点