Pick up the exactly center position of object in my code i use onmousedown function inside this function pick the click position i want center an object in the screen
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 //!?
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…