Created
August 10, 2021 12:48
-
-
Save andijakl/38bcd1effe29ea0cd5723bc1d289a92d to your computer and use it in GitHub Desktop.
Code part to attach an anchor to a plane in AR Foundation
This file contains hidden or 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
ARAnchor CreateAnchor(in ARRaycastHit hit) | |
{ | |
ARAnchor anchor; | |
// ... here, we'll place the plane anchoring code! | |
// If we hit a plane, try to "attach" the anchor to the plane | |
if (hit.trackable is ARPlane plane) | |
{ | |
var planeManager = GetComponent<ARPlaneManager>(); | |
if (planeManager) | |
{ | |
var oldPrefab = _anchorManager.anchorPrefab; | |
_anchorManager.anchorPrefab = _prefabToPlace; | |
anchor = _anchorManager.AttachAnchor(plane, hit.pose); | |
_anchorManager.anchorPrefab = oldPrefab; | |
Debug.Log($"Created anchor attachment for plane (id: {anchor.nativePtr})."); | |
return anchor; | |
} | |
} | |
// Otherwise, just create a regular anchor at the hit pose | |
// (see previous code snippet) | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment