0
개체를 Y 축으로 끌기위한 스크립트를 만들고 있습니다. 거의 끝났지 만 문제가 하나 있습니다. 개체를 클릭하면 개체의 중심이 마우스 위치로 이동 한 다음 중심을 항상 마우스 위치로 드래그합니다. 예를 들어 스프라이트의 아래쪽을 잡고있을 때 어떻게 만들 수 있습니까? 스프라이트의 중심은 그대로 있고 마우스 위치로 이동하지 않습니다. 내 스크립트는 다음과 같습니다.Unity3d 손가락 문제가있는 객체를 끌기
public Vector3 screenPoint;
public Vector3 offset;
void OnMouseDown(){
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag(){
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint), offset;
transform.position = new Vector3(transform.position.x, curPosition.y, transform.position.z);
}
고맙습니다.
질문이 하나 더 있습니다. 어떻게하면 움직임을 제한하고 최대 탑 스폿과 최대 봇 스팟을 설정하여 객체가 하나에서 다른 것으로 이동할 수 있도록 할 수 있습니까? – filipst
[Mathf.Clamp] (http://docs.unity3d.com/ScriptReference/Mathf.Clamp.html)를 사용하여 최대 및 최소 좌표를 제한 할 수 있습니다. –
대단히 감사합니다 :) – filipst