Skip to content

Instantly share code, notes, and snippets.

Last active August 10, 2021 13:09
What would you like to do?
Part 2 of the script to place holograms based on raycasts with AR Foundation
void Update()
// Only consider single-finger touches that are beginning
Touch touch;
if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; }
// Perform AR raycast to any kind of trackable
if (_raycastManager.Raycast(touch.position, Hits, TrackableType.AllTypes))
// Raycast hits are sorted by distance, so the first one will be the closest hit.
var hitPose = Hits[0].pose;
// Instantiate the prefab at the given position
// Note: the object is not anchored yet!
Instantiate(_prefabToPlace, hitPose.position, hitPose.rotation);
// Debug output what we actually hit
Debug.Log($"Instantiated on: {Hits[0].hitType}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment