Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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