Skip to content

Instantly share code, notes, and snippets.

@andijakl
Created August 10, 2021 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andijakl/98160d2b7e7eb5fa490590304937f68f to your computer and use it in GitHub Desktop.
Save andijakl/98160d2b7e7eb5fa490590304937f68f to your computer and use it in GitHub Desktop.
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