Created
August 10, 2021 12:33
-
-
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.
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
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