class CardMove : MonoBehaviour
{
Vector2 point; // 현재 마우스 위치
Vector2 Premouse; // 전 마우스 위치
GameObject clickObject;
void Start()
{
}
void Update()
{
point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetMouseButtonDown(0))
{
Premouse = point;
RaycastHit2D hit = Physics2D.Raycast(point, Vector2.zero, 0f);
if (hit.collider != null)
{
clickObject = hit.transform.gameObject;
}
}
if (Input.GetMouseButton(0))
{
Vector2 newMove = point - Premouse;
clickObject.transform.position += new Vector3(newMove.x, newMove.y);
Premouse = point;
}
}
}
드래그 함수 안쓰고 그냥 만들어봤는데
이게 왜 2배로 움직이지??
newMove에 0.5 곱해주면 제대로 되는데
이유를 모르겠네
Premouse = point는 뭐에 쓰는거?
전 위치 = 현재 위치 로 갱신
저 오브젝트가 어떻게 움직이려는건지는 잘 모르겠어서 그런데 newmove를 더한거면 현재위치는 point랑은 다른거아녀?
마우스로 클릭하면 그 다음부터 마우스 따라 움직이는거야 point - Premouse 이 차이만큼 오브젝트를 움직이게 해서 마우스를 따라다니는 원리야
해결했는데 스크립트는 맞았음. 카드 오브젝트 프리팹에 넣어놔서 카드수만큼 연산됬던거임 카드가 2장이라서 2배계산된거였음 카드 3장되니까 3배 되길래 딱 알아챘음 스크립트를 프리팹이 아니라 다른곳에 넣으니까 해결됐음
각자 카드에 선택됨 상태를 만들고 if(선택됨)을 해서 움직이는게 좋아보임