반응형
코드 작성
레이 캐스트를 활용합니다
using UnityEngine;
public class TouchEvent : MonoBehaviour {
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("터치된 오브젝트: " + hit.transform.name);
}
}
}
}
참고할만한 글
유니티 C# 모바일 터치로 3D 오브젝트 클릭 방법 간단 구현
코드 작성using UnityEngine;public class TouchHandler : MonoBehaviour{ void Update() { // 터치 입력이 있는지 확인 if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); // 터치가 방금 시작되었는지 확인 if (touch.phase == Tou
parksh3641.tistory.com
유니티 C# 마우스 좌표 Mouse Position 간단 구하기
코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MousePosition : MonoBehaviour { private void Start() { } void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = C
parksh3641.tistory.com
반응형