유니티게임 화면에선 공격기능이 잘 작동하는데 모바일로 빌드시 작동 불가
void Update()
{
// PC 환경: 마우스 클릭
if (Input.GetMouseButtonDown(0))
{
HandleAttack(Input.mousePosition);
}
// 모바일 환경: 터치 입력 처리
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began) // 손가락이 화면을 터치한 순간
{
HandleAttack(touch.position);
}
}
}
void HandleAttack(Vector2 screenPosition)
{
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
{
Debug.Log("UI 클릭 감지: 공격 불가");
return;
}
// 공격 실행
Debug.Log("공격 실행됨!");
AttackMonster();
}
클리과 더불어 터치하는 코드도 추가 작성 필요