Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Last active December 12, 2022 12:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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