void SendInputValue(Vector2 inputPos) { if (btnPressed) { Vector2 gabPos = (inputPos - startPos); if (gabPos.sqrMagnitude <= dragRadius * dragRadius) { touchCtrl.position = inputPos; } else { gabPos.Normalize(); touchCtrl.position = startPos + gabPos * dragRadius; } } else { touchCtrl.position = startPos; } Vector2 touchPosXY = new Vector2(touchCtrl.position.x, touchCtrl.position.y); Debug.Log(touchCtrl.position.x); Debug.Log(touchCtrl.position.y); Vector2 diff = touchPosXY - startPos; Vector2 normDiff = new Vector2(diff.x / dragRadius, diff.y / dragRadius); if (player != null) { player.OnTouchValueChanged(normDiff); } }
void SendInputValue(Vector2 inputPos) { if (btnPressed) { //컨트롤러의 기준 좌표로부터 입력받은 좌표 사이의 거리 구하기 Vector2 gabPos = (inputPos - startPos); //입력 지점이 기준 좌표로부터 일정 거리 안에 있으면 if (gabPos.sqrMagnitude <= dragRadius * dragRadius) { //현재 터치 좌표로 방향키 이동하기 touchCtrl.position = inputPos; } //입력 지점이 일정한 기준 좌표보다 크다면 else { //벡터 크기를 정규화하기 gabPos.Normalize(); touchCtrl.position = startPos + gabPos * dragRadius; } } else { //터치한 손을 놓으면 컨트롤러를 초기위치로 설정 touchCtrl.position = startPos; } Vector2 touchPosXY = new Vector3(touchCtrl.position.x, touchCtrl.position.y); Vector2 diff = touchPosXY - startPos; Vector2 normDiff = new Vector2(diff.x / dragRadius, diff.y / dragRadius); if (player != null) { //HeroMove.cs 스크립트 안에 있는 OnTouchValueChanged() 메소드 호출 player.OnTouchValueChanged(normDiff); } }