Last active
August 10, 2021 13:09
-
-
Save andijakl/1a65d595f57d4e11a96f7308ebdb5858 to your computer and use it in GitHub Desktop.
Part 2 of the script to place holograms based on raycasts with AR Foundation
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
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