Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Last active December 12, 2022 12:54
Show Gist options
  • Save hatsunea/c53f114e8961230eaa18398d0a682463 to your computer and use it in GitHub Desktop.
Save hatsunea/c53f114e8961230eaa18398d0a682463 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class AirTapGesture : MonoBehaviour
{
[SerializeField] private Camera ArCamera;
private void Update()
{
if (Input.touchCount <= 0) return;
var touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
// rayを照射
var ray = this.ArCamera.ScreenPointToRay(touch.position);
// Cubeをタップした場合はCubeを配置する
RaycastHit hit;
var hasHit = Physics.Raycast(ray, out hit);
if (hasHit)
{
var target = hit.collider.gameObject;
if (target.name.Contains("Cube"))
{
var clone = Instantiate(target); // Clone
clone.AddComponent<Rigidbody>();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment