Skip to content

Instantly share code, notes, and snippets.

@andijakl
Created August 10, 2021 12:33
Embed
What would you like to do?
First version of the code to create an anchor in AR Foundation based on the ARRaycastHit.
ARAnchor CreateAnchor(in ARRaycastHit hit)
{
ARAnchor anchor;
// ... here, we'll place the plane anchoring code!
// Otherwise, just create a regular anchor at the hit pose
// Note: the anchor can be anywhere in the scene hierarchy
var instantiatedObject = Instantiate(_prefabToPlace, hit.pose.position, hit.pose.rotation);
// Make sure the new GameObject has an ARAnchor component
anchor = instantiatedObject.GetComponent<ARAnchor>();
if (anchor == null)
{
anchor = instantiatedObject.AddComponent<ARAnchor>();
}
Debug.Log($"Created regular anchor (id: {anchor.nativePtr}).");
return anchor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment