Last active
December 12, 2022 12:54
-
-
Save hatsunea/c53f114e8961230eaa18398d0a682463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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